Question

I have say ActivityA, when i press the back button, I call moveTaskToBack(true) in order to put it in the background (onPause() is called). When I go and do other stuff in phone, the system will eventually destroy my ActivityA and onCreate() will be called when I return to my ActivityA. How can I resume the activity instead of creating it when this happens?

Many thanks!

Was it helpful?

Solution

I have to admit not being entirely known with moveTaskToBack();, but it doesn't sound to me like you can use this to affect the Activity life cycle.

It sounds more like simply effecting the 'breadcrumbs' you leave, which affects the way your back-button works. You're just placing your Activity to the back of this stack, so it won't get back with the back-button firstly I think.

Secondly, your Activity will not go into onPause when leaving it, but onStop. onPause is for when per example a dialog opens over your Activity.

You can't stop the system from destroying your Activity when needed, and you can't stop it from calling onCreate after this happens. You can use the Bundle savedinstancestate to save data in, so you don't have to re-fetch these from the database, internet, file dir or whatever.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top