In my Activity A, I add some fragments (standard case). I've checked, on my Android phone settings, "Don't keep Activities" to simulate worst application behavior.
So, when this Activity A restart, I do that in onCreate() method, to clean all my previous fragments added :
FragmentManager fm = getSupportFragmentManager();
List<Fragment> al = fm.getFragments();
if (al != null) {
for (Fragment frag : al) {
if (frag != null) {
getSupportFragmentManager().beginTransaction().remove(frag).commit();
fm.popBackStack();
}
}
}
But unfortunately I can see in the logs, these kind of informations:
Successful to getNewsFeedInteractionsList() #2
Successful to getNewsFeedInteractionsList() #2
Successful to getNewsFeedUserList() #Suivis
Successful to getNewsFeedUserList() #Populaire
Successful to getNewsFeedUserList() #Populaire
Successful to getNewsFeedUserList() #Suivis
You can see, all these fragments are appears twice ...
Thanks for your help!
While adding fragments you can set tags. Based on those tags handle duplicate addition in onCreate
. As well you use savedBundle
instance for null check
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.