[英]Resume previous activity from broadcast receiver
here's my problem: 这是我的问题:
At the moment I have a broadcastReceiver which is able to start a new instance of activity A when the call takes place. 目前,我有一个broadcastReceiver,它能够在呼叫发生时启动活动A的新实例。 If I start activity A from there with "FLAG_ACTIVITY_SINGLE_TOP", I get the error
如果我从那里开始活动“ FLAG_ACTIVITY_SINGLE_TOP”,则会收到错误消息
Calling startActivity() from outside of an Activity
context requires the FLAG_ACTIVITY_NEW_TASK flag.
Is this really what you want?
But I don't want a new task, I want to RESUME activity A 但我不想执行新任务,我想恢复活动A
Thanks a lot! 非常感谢!
EDIT: Perhaps I could simply simulate a click on the BACK-button? 编辑:也许我可以简单地模拟一下“返回”按钮上的点击?
Considering your use case - BroadcastReceiver that doesn't have a tasks in which to start the activity - singleTask
in the manifest should do what you want. 考虑到您的用例-没有启动活动的任务的BroadcastReceiver-清单中的
singleTask
应该执行您想要的操作。
"singleTask" The system creates a new task and instantiates the activity at the root of the new task.
“ singleTask”系统创建一个新任务,并在新任务的根目录处实例化活动。 However, if an instance of the activity already exists in a separate task, the system routes the intent to the existing instance through a call to its onNewIntent() method, rather than creating a new instance.
但是,如果活动的实例已经存在于单独的任务中,则系统将通过对其onNewIntent()方法的调用将意图路由到现有实例,而不是创建新实例。 Only one instance of the activity can exist at a time.
一次只能存在一个活动实例。
Note: Although the activity starts in a new task, the Back button still returns the user to the previous activity.
注意:尽管活动在新任务中开始,但是“后退”按钮仍使用户返回上一个活动。
Taken from: http://developer.android.com/guide/components/tasks-and-back-stack.html 摘自: http : //developer.android.com/guide/components/tasks-and-back-stack.html
Have you tried using FLAG_ACTIVITY_REORDER_TO_FRONT
? 您是否尝试过使用
FLAG_ACTIVITY_REORDER_TO_FRONT
?
http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_REORDER_TO_FRONT http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_REORDER_TO_FRONT
It seems to do exactly what you need. 它似乎完全可以满足您的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.