通知中的活动顺序
我有关于 Android 通知和活动顺序的问题。
我有以下场景:
我将 Activity_Main 作为我的第一个活动,它执行一些任务。当按下“后退”按钮时,它会生成通知。 Activity_Main 有以下调用(onKeyDown()
、OnPause()
、OnStop()
、OnDestroy()
)。当用户单击通知图标时,Activity_Main 启动,调用顺序为 (OnCreate()
, OnResume()
)。这很好。
现在 Activity_Main 包含使用 StartActivityForResult()
api 启动 Activity_Second 的按钮,并生成任务进度通知,函数调用为 (onSaveInstance()
, OnPause(),<代码>OnStop())。如果用户通过
setResult(result)
按 Activity_Second 上的后退按钮,则一切正常。但是,如果用户选择“通知”图标(activity_seconds 可见),则 Activity_main 上的新实例(onCreate()
、OnResume()
)启动。我想要的是 Activity_Second 应该关闭它,并且应该调用 Activity_Main 的 onResume() 。现在 Activity_Main(第二个实例)、Activity_second、Activity_Main(第一个实例)位于活动堆栈上。
我在生成通知时设置了以下标志。
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
还有什么其他方法可以解决这个问题?
I have a question regarding Android Notification and activity order.
I have following scenario:
I have Activity_Main as my first activity, which performs some task. When BACK button is pressed It generates notification. Activity_Main has following calls (onKeyDown()
, OnPause()
, OnStop()
, OnDestroy()
). When user clicks the notification icon Activity_Main is started and call sequence is (OnCreate()
, OnResume()
). Which is fine.
Now Activity_Main contains button which starts Activity_Second using StartActivityForResult()
api and also generates notification of task progress, function calls are (onSaveInstance()
, OnPause()
, OnStop()
). If user presses back button on Activity_Second by setResult(result)
, everything works fine. But if the user selects the Notification icon (activity_seconds is visible) then new instance on Activity_main (onCreate()
, OnResume()
) started. What i want is Activity_Second should close it and (onResume()
of Activity_Main) should be called. Right now Activity_Main(2nd instance), Activity_second, Activity_Main(1st instance) is on activity stack.
I have following flags set while generating notification.
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
What is other way to solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将这些标志添加到您的意图后尝试:
try after adding these flags to your intent:
@ vineet,这没有帮助。
并
一起帮助我解决了这个问题......
从此链接
@ vineet, it didnt help.
and
togather helped me to solve this...
from this link