简体   繁体   中英

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!

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.在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM