Clear program fragment

What is the best way to clear a piece of software back?

I implemented on-screen navigation using only one action and a set of fragments. I would like to have a method that displays the user on the login screen (when the logout time expires) and clears the entire fragment history, what is the best way to do this? I found some answers here, but I do not know which is the best ... Thanks in advance!

I am currently using this

public void clearBackStack() {
    FragmentManager fragmentManager = holder.getSupportFragmentManager();

    while (fragmentManager.getBackStackEntryCount() != 0) {
        fragmentManager.popBackStack(null, 0);
    }
}

However, sometimes I get outOfMemoryException

+3
source share
2 answers

This is a pretty old question at the moment. Anyway, I tried my code and it looks like you have an infinite loop.

popBackStack(null, 0) , . while , . popBackStack , , while .

, fragmentManager.popBackStackImmediate() .

+11

FragmentManager.popBackStack(), .

fragmentManager.popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);

.

0

All Articles