简体   繁体   English

在Android平台上保持活动(或应用)运行状态的最佳方法是什么?

[英]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.

相关问题 Android平台上的Phonegap应用-保持应用运行 - Phonegap app on Android platform - keep app running 保持 Android 应用 24/7 全天候运行的最佳方法是什么? - What is the best approach to keep Android app running 24/7? 在Android应用程序中保留数据库引用的“最佳实践”方法是什么? - What is the “best practice” way to keep a database reference in an Android app? 保持身份验证状态的最佳方法是什么 - What is the best way to keep authentication state 在Android中制作多活动应用的最佳方法 - Best way to make a multi activity app in android Android应用,活动状态(正在运行,未运行,前景/背景) - Android App, Activity State (Running, Not Running, Foreground/ Background) 离开并在Android-App中重新输入后,保持Activity UI的状态 - Keep state of Activity UI after leaving and reentering it in Android-App 处理活动状态的最佳方法 - Best way to handle activity state 保持活动处于暂停状态-Android - Keep activity in paused state - Android 检查 Android 应用程序是否在 Windows11 的 android 的 windows 子系统上运行的最佳方法是什么? - What is the best way to check that an Android app is running on windows subsystem for android of windows11?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM