[英]Don't kill app when removed from recent apps
I want my application to keep running when the user removes the application from the recent apps screen . 当用户从“ 最近的应用程序”屏幕中删除应用程序时,我希望我的应用程序继续运行。
Current Scenario: 当前方案:
The activity stack: A --> B --> C ( foreground service started from this activity). 活动堆栈:A-> B-> C(从此活动启动的前台服务 )。 Now, if the user removes the application from the recent apps screen then the service keeps running but the activity A,B and C are killed . 现在,如果用户从最近的应用程序屏幕中删除了该应用程序,则该服务将继续运行,但活动A,B和C被杀死 。 Now, if the user launch the application then the activity A is started. 现在,如果用户启动应用程序,则活动A将启动。
Result required: 所需结果:
I want the application to start directly with activity C with the state before it was previously killed. 我希望应用程序直接从活动C开始,其状态为之前被杀死的状态。
I would appreciate any suggestions and thoughts on this topic. 我将对此主题提出任何建议和想法。 Thank you. 谢谢。
Here is the nearby solution you can try.. might be helpful. 这是您可以尝试的附近解决方案。可能会有所帮助。 You can use the method of your application class, where you can track your current running activity. 您可以使用应用程序类的方法,在其中可以跟踪当前的运行活动。 For opening the last activity maintain and save a variable in SharedPreferences
on activity paused/or created(whatever work) in below method. 要打开上一个活动,请按以下方法在已暂停/或创建的活动(无论工作如何)下在SharedPreferences
维护并保存一个变量。
private void setupActivityListener() {
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
if (activity instanceof MainActivity) {
Log.e(TAG, "**************** MainActivity Created *******************");
}
//Log.e(TAG, "**************** onActivityCreated *******************");
}
@Override
public void onActivityStarted(Activity activity) {
//Log.e(TAG, "**************** onActivityStarted *******************");
}
@Override
public void onActivityResumed(Activity activity) {
CancelNotification();
activeActivity = activity;
//Log.e(TAG, "**************** onActivityResumed *******************");
}
@Override
public void onActivityPaused(Activity activity) {
activeActivity = null;
//Log.e(TAG, "**************** onActivityPaused *******************");
}
@Override
public void onActivityStopped(Activity activity) {
//Log.e(TAG, "**************** onActivityStopped *******************");
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
}
@Override
public void onActivityDestroyed(Activity activity) {
if (activity instanceof MainActivity) {
Log.e(TAG, "**************** MainActivity Destroyed *******************");
}
}
});
}
And when open the app, check at startup what was the last activity.. if it wasn't MainActivity then redirect to the desired activity... 并在打开应用程序时,在启动时检查什么是最后一个活动..如果不是MainActivity,则重定向到所需的活动...
For state you can save it to bundle or some other source.. like in sharedpreferance. 对于状态,您可以将其保存到捆绑包或其他一些来源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.