Skip to content Skip to sidebar Skip to footer

Handling Dvm Killing Your Activity

I have an activity which fetches huge set of data from the network and i want to handle the scenario for this activity if the DVM decides to destroy this activity (due to low memor

Solution 1:

Depending on the data you need to savior you could pass in the data (if it's primitive types) into the Bundle of the Activity and override the onPause method of the activity. The onPause method will be called whenever the Activity closes.

See the activity lifecycle for reference http://developer.android.com/reference/android/app/Activity.html

There are other ways to save the data - you could write it directly to a file on the SD card and then close the stream in the onPause method if the Activity is closed by the OS without finishing the data.

Then when the Activity is opened again you call the onResume method of the Activity and read the data saved inside the Bundle or the file written to the SD card.

Post a Comment for "Handling Dvm Killing Your Activity"