Jesse
Jesse

Reputation: 2684

Android app resume issues

In my app, I have a loading view that sets up the app by going out to an API and bringing back some startup info to store. I store it temporarily in an Application class. An example of the type of data is lets say a list of servicable cities.

The flow is:

Loading View -> Main Menu -> etc etc

If I exit out of the app and come back, it usually starts with Main Menu view and hits onresume and everything is fine. But sometimes if I wait a while and the OS clears some memory maybe, I come back and it again goes to Main Menu but this time starts from scratch for that view by calling onCreate. But it seems like the application data is wiped.

I am just wondering why, if it is wiping the application data, is it not just starting up the app from scratch?

Is there some directive in the manifest I can make to make it do this? Keep in mind, I dont want it to restart the app when coming back into the app from a pause. Only when the OS has cleared the application data...

Upvotes: 1

Views: 745

Answers (1)

slayton
slayton

Reputation: 20319

When the application is closed to free up memory the state of stored in your Application class is lost. You can save information that will persists even if you application gets closed in a few ways.

One is to use shared preferences: Making data persistent in android

The other is to use Bundles which is probably more along the lines of what you need: Saving Android Activity state using Save Instance State

Upvotes: 2

Related Questions