简体   繁体   English

从最近的应用程序中删除后,请不要杀死应用程序

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

相关问题 从最新应用程序中删除应用程序后,自定义静态广播接收器不起作用 - custom static broadcastreceiver not working when app is removed from recent apps 从最近的应用程序中删除应用程序时,“前台”服务将被终止 - “foreground” service is killed when App is removed from recent apps Android,从“最近的应用”中删除应用时取消通知 - Android, cancel notification when app is removed from “Recent apps” 从最近的应用程序中删除应用程序后,IntentService停止工作 - IntentService stops working when app is removed from recent apps 从最近的应用程序列表中删除应用程序时,将调用哪些生命周期事件? - Which lifecycle events are called when an app is removed from recent apps list? android中的GCM,当从“设备最近的应用”部分中删除该应用实例时,未显示预期的活动 - GCM in android, not showing the intended activity when the app instance is removed from the Devices RECENT Apps section 从 Android 12 中的最近应用程序中删除应用程序时,音乐播放器前台服务停止 - Music Player Foreground service Stops when App is removed from recent apps in Android 12 android-从最新应用中删除的应用取消了前台通知 - android - foreground notification is cancelled on app removed from recent apps 从最近的应用程序中删除应用程序后继续服务 - continuing service after app is removed from recent apps 从最近的应用程序列表中删除后,我的应用程序被杀死 - My application is getting killed when removed from recent apps list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM