问题
I am stuck with situation for resuming my fragment when I am coming back from another fragment.
Scenario :
I have a Fragment A
. Now I am opening multiple fragment with in Fragment A
say : A1, A2, A3 ...
using a frame layout.
Now I am initiating a new Fragment say Fragment B
from one of A1/A2/A3 ...
I am performing some action over Fragment B
and now when I Pop Out my Fragment B
then I am not able to get onResume() of Fragment A
Just need to get onResume() while I get back from Fragment B
Any help over this needed!
Highly appreciated!
Thanks.
回答1:
Launch fragment A1, A2, A3 with childfragment manager from fragment A and launch fragment B with main fragment manager.
For Example : To perform any fragment operation we have two fragment manager, If you are performing any fragment operation within a fragment you should use getChildFragmentManager() inplace of getSupportFragmentManager().
Now here, to launch fragment A1, A2 and A3 you should use getChildFragmentManager() and When launching fragment B you should use getSupportFragmentManager(). So when you press back from fragment B you will get onResume callback in fragment A.
回答2:
When you have added your fragment B, have you added the transaction to the backstack with this command: addToBackstack(null); by this way, you can restore the previous state when you press back on fragment B and return to fragment A.
来源:https://stackoverflow.com/questions/31584508/fragment-onresume-and-backstack-issue