返回活动,即使它没有历史记录 = true
我需要知道以下流程是否正常: 活动 A onPause 被调用,因为活动 B 获得了焦点,但几秒钟后,当活动 B 完成且在 onStop 之前,活动 A 被调用。 Activity A 的 onDestroy 被调用,Activity A(同一实例)的 onResume 被调用。 我在清单中的活动 A 定义中没有 noHistory=true 。
我认为一旦活动失去焦点, noHistory=true 的活动实例将永远不会被返回。
I need to know if the following flow is normal:
Activity A onPause is called because activity B took the focus, but a few seconds later, when activity B is finished and before onStop & onDestroy of Activity A were called, Activity A (same instance) onResume is called.
I have noHistory=true in the activity A defition in the manifest.
I thought that an instance of an activity with noHistory=true will never be returned once the activity has lost it's focus.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您描述的调用
ActivityA.onResume()
的行为不正确。我怀疑您的 AndroidManifest.xml 文件中有拼写错误。您可以发布它并向我们展示吗?onStop()
和onDestroy()
的时间定义较少。下面是一个有效的示例,但在用户点击后退按钮之前不会调用onStop()
和onDestroy()
(但onResume()
> 从未被调用)。如果我在启动 ActivityB 后调用finish()
,那么它们会提前在 ActivityA 上调用。不带 finish() 的输出:
带完成的输出:
HelloAndroidActivity.java:
GoodbyeAndroidActivity.java:
main.xml
goodbye.xml:
AndroidManifest.xml:
The behavior you describe with
ActivityA.onResume()
being called is not correct. I suspect a typo in your AndroidManifest.xml file. Can you post it and show us?The timing of
onStop()
andonDestroy()
are a little less defined. Here's an example that works, butonStop()
andonDestroy()
aren't called until the user hits the back button (butonResume()
is never called). If I callfinish()
after launching ActivityB then they're called on ActivityA earlier.OUTPUT without finish():
OUTPUT with finish:
HelloAndroidActivity.java:
GoodbyeAndroidActivity.java:
main.xml
goodbye.xml:
AndroidManifest.xml:
听起来@Sam Quest 有你的答案。在启动新活动之前调用 onFinish()。如果由于用户导航而发生这种情况,那么您的活动应该完成,但我不知道是否有任何保证何时完成。如果您的 LoginActivity 正在创建活动,那么调用 onFinish() 听起来像是正确的做法,而不是解决方法。
It sounds like @Sam Quest has your answer. Call onFinish() before launching a new activity. If it happened due to user navigation then your activity should be finished but I don't know if there is any guarantee when. If your LoginActivity is creating the activity then calling onFinish() sounds like the right thing to do, not a workaround.
用于活动结果。那么你的问题就会解决。
use on activity result. Then your problem will solve.