异常java.lang.IllegalStateException:在onSaveInstanceState

时间:2017-08-22 04:39:00

标签: android android-fragments crash android-support-library

异常java.lang.IllegalStateException:在onSaveInstanceState之后无法执行此操作

  

android.support.v4.app.FragmentManagerImpl.checkStateLoss   (FragmentManager.java:1842)   android.support.v4.app.FragmentManagerImpl.enqueueAction   (FragmentManager.java:1860)   android.support.v4.app.BackStackRecord.commitInternal   (BackStackRecord.java:650)   android.support.v4.app.BackStackRecord.commit   (BackStackRecord.java:609)   的> com.bharat.example.adapter.Articles_Adapter $ MyViewHolder.onClick   (Articles_Adapter.java:147)

     

android.view.View.performClick(View.java:5201)   android.view.View $ PerformClick.run(View.java:21163)   android.os.Handler.handleCallback(Handler.java:746)   android.os.Handler.dispatchMessage(Handler.java:95)   android.os.Looper.loop(Looper.java:148)   android.app.ActivityThread.main(ActivityThread.java:5443)   java.lang.reflect.Method.invoke(Method.java)   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run   (ZygoteInit.java:728)com.android.internal.os.ZygoteInit.main   (ZygoteInit.java:618)

在FragmentTransaction commit()时发生了崩溃。

FragmentTransaction transaction = ((Content_Activity) main).getSupportFragmentManager().beginTransaction();
                transaction.setCustomAnimations(R.anim.left_in, R.anim.left_out, R.anim.right_in, R.anim.right_out);
                transaction.replace(R.id.fragment_frame, fragment, "web");
                transaction.addToBackStack("home");
                transaction.commit();

使用android.support.v4.app.FragmentTransaction

1 个答案:

答案 0 :(得分:2)

添加此行。它对我很好。

transaction.commitAllowingStateLoss()