noloman
noloman

Reputation: 11975

Executing fragment transactions after onPause()/onStop()

I have been reading this great article but unfortunately, in my code I can't make sure that I'm not executing these transactions on a callback. That's why I'm wondering: is there any way to prevent the IllegalStateException perhaps by checking Activity.isFinishing() or any other method related to the Activity lifecycle?

Thanks a lot in advance

Upvotes: 0

Views: 630

Answers (1)

Gurkonier
Gurkonier

Reputation: 116

You can check whether the FragmentManager's state is saved with:

fragmentManager.isStateSaved()

If this is true, you can't run a fragment transaction anymore.

If it's not working, try to run commitAllowingStateLoss() instead of commit().

Upvotes: 2

Related Questions