2

So, if I want to e.g. replace Fragment, I can do the following:

    ft.replace(R.id.frame, newFragment);
    if (mFragmentManager.isStateSaved()) {
        ft.commitAllowingStateLoss();
    } else {
        ft.commit();
    }

The above code will not throw the notorious IllegalStateException if it's run after the state is saved.

However, when it comes to popping the backstack, I can't find an analogously safe way of doing things.

So, is there any safe way to pop FragmentManager's backstack after the state had already been saved?

Vasiliy
  • 16,221
  • 11
  • 71
  • 127
  • Check out this [article about Fragment Transactions & Activity State Loss](https://www.androiddesignpatterns.com/2013/08/fragment-transaction-commit-state-loss.html), Described the issue in details and **How to avoid the exception**. – Khaled Lela Sep 04 '18 at 11:54
  • @KhaledLela, I'm familiar with this article. It doesn't address the question of popping the backstack. – Vasiliy Sep 04 '18 at 11:57
  • Please have a look to comments related with the article. – Khaled Lela Sep 04 '18 at 12:00
  • @KhaledLela, I did. Still can't see anything that would look as an answer to my question. – Vasiliy Sep 04 '18 at 12:09

0 Answers0