Reputation: 31
I have this listview that gets populated with the data that is downloaded from the internet. Hence in the onCreate() method, I will run the async task to download the information and put it into the listview.
I placed a boolean value to whether if the list is downloaded or not during the saveInstanceState() method, this will work if the user gets out of the app from the home button and returns. However, when the user exits the program through the back button, the saveInstanceState() method is not run.
I do not want to download the list again, how can I check whether if it's downloaded before?
Upvotes: 0
Views: 71
Reputation: 17622
You can override Activity.onBackPressed() and save your state there as well.
Also, you can do
void onPause() {
if(isFinishing()) {
// save your state. maybe you'd be better off with using preferences (or other things suggested by people here), so you don't need to worry about the instance state.
}
}
Upvotes: 0
Reputation: 11422
Check this out: Implementing the lifecycle callbacks http://developer.android.com/guide/topics/fundamentals/activities.html
Use the callbacks to get noticed what happens to your activity and react if nesseceray.
You can use the Shared Preferences to store key-value data: http://developer.android.com/guide/topics/data/data-storage.html
Upvotes: 1
Reputation: 40002
If you want to persist data beyond the LifeCycle of the application, you'll need to store it outside the Bundle.
Your options are:
I'd suggest a private Internal Storage file for saving your data.
Upvotes: 0