Android-How to detect on resume that my app was killed by VM?

断了今生、忘了曾经 提交于 2019-12-05 10:43:44

When onCreate (Bundle savedInstanceState) is called, check that savedInstanceState is not null. As stated by onCreate :

savedInstanceState If the activity is being re-initialized after previously being shut down then this Bundle contains the data it most recently supplied in onSaveInstanceState(Bundle). Note: Otherwise it is null.

See also onSaveInstanceState() which is not part of the normal lifecycle but is called before the activity is killed.

Note : if the user does A ----> B ----> C --back--> B ----> C, the second time C is created the passed bundle will be null, as it is a new instance, not the same recreated after being killed.

Basically: look at the picture on this page: http://developer.android.com/reference/android/app/Activity.html

the various functions that are called in different situations are onCreate, onStart and onResume.

My suggestion would be: implement your own Application and if the onCreate() is called, the app was killed in background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!