Skip to content Skip to sidebar Skip to footer

Android Is Killing My Application Whenever Startactivityforresult Is Called

Well, in my application I'm using default camera and gallery of Android with startActivityforResult as; Intent i = new Intent('android.intent.action.PICK', M

Solution 1:

You need a good read of the must-read-before-you code article : http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle

You activitie can and will be killed by Android if memory is low. But it will be notified and there is a very well defined way of dealing with this.

This is the reason of existence of the Bundle savedInstanceState in all your activities oncreate : public void onCreate(Bundle savedInstanceState)

During the onpause of your app, you should save all you need to recreate the state your app is in and during the oncreate of your app you should check if you are coming back with a full savedInstanceState and restore your app from there.

Good luck.

Solution 2:

Have you considered using some type of persistent storage? Save the data you need saved in persistent storage (shared preferences, db, file system, etc.) before you call the new intent, with some sort of reconstruction flag. Then if the activity calls onCreate and the flag is up, you can restore the previous activity state. Make sure to clear the reconstruction flag when its not needed, which should be in onResume.

Edit:

onSaveInstanceState seems to be the way for data local to the activity.

Post a Comment for "Android Is Killing My Application Whenever Startactivityforresult Is Called"