关闭父活动并启动新活动
我有一个基本活动和一些子活动,如 A、B、C 和 D。这里 A 是 B、C 和 D 的父级,意味着当 B、C 或 D 完成时,控制权返回到 A。现在我想要的是当 Activity 说 D 完成时,它也会关闭 A(父级)并启动一个新的 Activity(比如 E)。这里 E 应该是堆栈上唯一的。 它的意思是关闭所有不可见或等待结果的活动并启动一个新的活动(E)。
I have a base activity and some child activities like A, B, C and D. Here A is parent of B, C and D means that when either B, C or D finishes, control comes back to A. Now what I want is that when Activity say D finishes, it also close A (parent) and launch a new one say E. Here E should be the only on stack.
Its mean close all the activities that are invisible or waiting for result and launch a new one (E).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道这是否可行,但您可以尝试一下:
从活动 A 中,使用 startActivityForResult() 启动活动 B 以获得结果,
设置一个结果,该结果将通知 A 也完成,
在 B 中调用 finish()
然后 。 A 收到 B 的结果,A 也调用自己的 finish() 。
在那里你可以开始另一项活动。
为此,您可以为多个已启动的活动设置请求代码作为结果,并检查 onActivityResult() 来比较结果代码
I don't know if this will work, but you could try it:
From Activity A, start activity B for a result using startActivityForResult()
set a result that will inform A to finish as well,
Call finish() in B.
When A receives that result from B, A calls finish() on itself as well.
and there you can start another activity.
for this you can set the request code for more than one activity which was start as for result and check into onActivityResult() to compare the result code
尝试为广播接收器注册所有活动。当 D 将要完成让它广播时,通过听此完成所有活动并在完成任何活动之前开始新的活动。
Try to register all the activity for broadcastreceiver.. When D is going to finish let it Broadcast, by listening to this finish all the activity and start new one before finishing anyone of the activity..