FLAG_ACTIVITY_REORDER_TO_FRONT和startActivityForResultFLAG_ACTIVITY_REORDER_TO_FRONT、startActivityFor

2023-09-07 16:47:36 作者:清花照凉颜

活动一开始b使用startActivityForResult,和B开始下使用startActivity。在此之后,活动堆栈A B C

Activity A started B using startActivityForResult, and B started C using startActivity. After that, the activity stack is A B C.

现在假设,C使用FLAG_ACTIVITY_REORDER_TO_FRONT标志使startActivity呼叫B,那么活动的堆栈将成为AC,B。

Now suppose, C makes startActivity call on B using FLAG_ACTIVITY_REORDER_TO_FRONT flag, then the activity stack will become A C B.

我的问题是,目前,在B完成本身,将onActivityResult()的调用由于B的退出?

My question is, now, if B finishes itself, will onActivityResult() in A be called due to B's exiting?

感谢。

推荐答案

评审通过的finish():

打电话当你的活动做   和应关闭。该   ActivityResult传播回   凡经推出,你   onActivityResult()。

Call this when your activity is done and should be closed. The ActivityResult is propagated back to whoever launched you via onActivityResult().

这使我相信,A将获得B的结果,即使C是在两者之间。

This leads me to believe that A will get B's result even if C is in between the two.

修改 - 经过一些测试中,我发现了一些有趣的交互,这里

Edit - after some testing I discovered some interesting interactions here.

事件的顺序,一些日志记录后:

The order of events, after some logging:

系统启动 乙开始 下开始 乙恢复(带有FLAG_ACTIVITY_BRING_TO_FRONT) 乙完成 ç恢复(这是在B) ç完成 一个简历,并得到B的结果 A started B started C started B resumed (with FLAG_ACTIVITY_BRING_TO_FRONT) B finished C resumed (it was under B) C finished A resumes and gets B's result

在换句话说,A得到B的结果如预期,但它发生的ç完成后和A重新开始。

In other words, A gets B's result as expected, but it happens after C finishes and A is resumed.