从“最近"打开应用程序会在Android中打开旧活动吗? [英] Opening the App from Recents opening the old activity in Android?

查看:72
本文介绍了从“最近"打开应用程序会在Android中打开旧活动吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个活动:启动器,MainActivity(SingleTask),NotificationActivity,ExampleActivity.

I have 4 Activities: Launcher, MainActivity(SingleTask), NotificationActivity, ExampleActivity.

当用户单击通知时,会打开 NotificationActivity ,然后 ExampleActivity 并完成 NotificationActivity .

When the user clicks on the notification, NotificationActivity opens then ExampleActivity and finishes the NotificationActivity.

当我按回 MainActivity 时.现在,如果我按回去,该应用程序将关闭.如果用户随后从最近的任务中打开应用,则 NotificationActivity 将打开,然后 ExampleActivivty .但是,如果用户从图标打开应用程序,则启动器活动会打开,然后是MainActivity.

When I press back MainActivity opens. Now if I press back, the application gets closed. If the user then opens the app from the recent Tasks, NotificationActivity opens then ExampleActivivty. But if the user opens the app from the icon, Launcher Activity opens then MainActivity.

如何处理这种情况?

推荐答案

我对这个问题的回答恰好涵盖了这个问题:

Exactly this problem is covered in my answer to this question:

从通知意图中删除数据

从最近任务列表中选择应用程序时,Android会记住该应用程序最初的启动方式(在您的情况下,通过Notification启动),并以相同的方式再次启动该应用程序.可以将其视为错误或功能,具体取决于您期望发生的情况.

When you select your app from the list of recent tasks, Android remembers how the app was originally launched (in your case, via Notification) and starts the app again the same way. This can be considered a bug or a a feature, depending on what you expect to happen.

我在回答中提出了一些建议,您可以用来解决它.

I've got a few suggestions in my answer that you can use to deal with it.

这篇关于从“最近"打开应用程序会在Android中打开旧活动吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆