I have one Activity with 3 fragments which form a workflow to collect user input. Normally, Fragment A is the first fragment -> Launches B -> Launches C. B is supposed to launch A if the back button is pressed, and similarly C's Back button is supposed to launch B.
However, in some cases, A is supposed to launch C directly, and then C's back should launch A again.
I prefer that C should not know who launched it. I.e. I want C's "backstack" to operate without C knowing who launched it.
I tried using the usual addToBackstack approach, but I'm facing a problem when the Activity gets killed after the user lets the app go into the background while C was open.
答案 0 :(得分:0)
Android开发者+ Adam Powell在这个精彩视频中找到了一些答案: Fragments: Google I/O 2016
总之,Fragments和Fragment BackStack被认为是应用程序导航状态的一部分,因此,只要我在启动活动时不会使用后端堆栈,操作系统也会恢复FragmentBackStack因此,即使重新创建活动,BackStack也会知道谁发起了C(A或B)。因此,popBackStack将根据需要从C移动到A或B.