androidandroid-intentandroid-activityandroid-fragments

error java.lang.RuntimeException: Unable to destroy activity IllegalStateException: Can not perform this action after onSaveInstanceState


I'm new to android development. I am working on a small project and i have encountered a bug that i have been trying to solved it for almost a day.

So i have two Activity:

  1. LoginpageActivity extends Activity
  2. MainPageFragment extends FragmentActivity

In MainPageFragment i have 4 buttons on the top of the screen, and a fragment below those buttons. Those 4 buttons stay there all the time as long as I'm log in. whenever i press one of the 4 buttons. The fragment ui below those buttons will change.

The name of those buttons are : Home, Profile, Mode, exit

Now the problem is, when i press Home button, the fragment page has two button: Offer and Request. When i press one of the two, it will jump to a page contains GOOGLE MAP.

If i press hardware BACK and try to go back to login page. The app will crash and say:

error java.lang.RuntimeException: Unable to destroy activity IllegalStateException: Can not perform this action after onSaveInstanceState

But i don't have problem when i press BACK in other fragment page where there is no GOOGLE MAP. I think it's GOOGLE MAP but i can't debug it.

Can anyone pls give me a hint? i'm really appreciate it. Thanks


Solution

  • Please try using commitAllowingStateLoss() instead of commit() when you push your fragment.

    transaction.commitAllowingStateLoss();