简体   繁体   中英

What is the best way for keep running state of activity(or app) on android platform?

I gonna find out the way to start my app's main activty from service when the main activity is not forground running. For example in the case the activity is destroyed while executing for crash, need to start activity again. I 'd like to create one service for it to check my activity's running status. if not running my activity my service would start the main activity again so always my activiy keep running status except to be finished by user. What is the best way? Kindly recommend me. Thanks.

If your activity have multiple instance, you can add an static variable such as static int activeInstance = 0; or place it in your SharedPreference and increase it every time an instance of the activity is called.

If you are sure that the activity can only have on instance running at a time you can place android:launchMode="singleInstance" inside that activity in the Manifest.xml file. You can read in more detail here http://developer.android.com/guide/topics/manifest/activity-element.html


Hope that help :D

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