Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart application after Android kills it

As far as I know, Android kills an application after sometime if the user is not interacting with it, in order to save memory. If the user goes back to the application, the last activity is displayed again. What I would like to do is that when this situations occurs, I always would like to restart from my main activity. But only if my application was killed, not in other scenarios.

Is there any way to do that? in the manifest for example?

Thanks in advance!

like image 594
Finuka Avatar asked Jul 20 '11 13:07

Finuka


1 Answers

You can check whether an Activity has been resumed by checking if the bundle in the onCreate method is null:

if(savedInstanceState != null)

If it isn't null, your activity has been resumed from being killed.

If you're simply pausing your activity onResume() is called over onCreate().

See the documentation here for the Activity Lifecycle. enter image description here

like image 147
Graeme Avatar answered Sep 22 '22 01:09

Graeme