[英]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;
如果您的活动有多个实例,则可以添加静态变量,例如
static int activeInstance = 0;
or place it in your SharedPreference
and increase it every time an instance of the activity is called. 或将其放在您的
SharedPreference
并在每次调用活动实例时将其增加。
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. 如果您确定该活动一次只能在实例上运行,则可以将
android:launchMode="singleInstance"
放在该活动的Manifest.xml
文件中。 You can read in more detail here http://developer.android.com/guide/topics/manifest/activity-element.html 您可以在http://developer.android.com/guide/topics/manifest/activity-element.html上详细了解
Hope that help :D 希望对你有帮助:D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.