java.lang.IllegalStateException: Failure saving state: active has cleared index in fragment

℡╲_俬逩灬. 提交于 2019-12-03 10:30:27

The state of your fragments is automatically saved and restored, there is no need to do anything in your onSaveInstanceState method. Don't hold any references to your Fragments in your Activity (in your case currentFragment, mContent), if you need a certain Fragment, get it from FragmentManager by e.g. findFragmentByTag.

Possible problem with reading fragment stat between detach and attach.

Try to use something like this:

FragmentTransaction ft = fragmentManager.beginTransaction();

//ft.detach(fragment).attach(fragment).commitAllowingStateLoss(); // crashing

ft.replace(getView().getId(), fragment).commitAllowingStateLoss(); // not crashing
S. Alawadi

Try to change

 @Override
public void onBackPressed() {
    if (0 == getSupportFragmentManager().getBackStackEntryCount()) {

to

 @Override
public void onBackPressed() {
    if (getSupportFragmentManager().getBackStackEntryCount() < 1 ) {

I hope this works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!