1

I got this exception in my app for once, now I don't understand what is this and not able to recreate it also.

Can anybody help me with this. Thanks in advance

Fatal Exception: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
   at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1489)
   at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:584)
   at android.support.v4.app.FragmentActivity.onBackPressed(FragmentActivity.java:169)
   at com.explorelife.UI.PropertyDetailsScreen.onBackPressed(PropertyDetailsScreen.java:310)
   at com.explorelife.UI.PropertyDetailsScreen.onClick(PropertyDetailsScreen.java:716)
   at android.view.View.performClick(View.java:4785)
   at android.view.View$PerformClick.run(View.java:19884)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:135)
   at android.app.ActivityThread.main(ActivityThread.java:5343)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
hArsh
  • 111
  • 1
  • 10

3 Answers3

0

View.performClick was processed after onSaveInstanceState. It seems you finish your Activity on click. We can reproduces the crash if you very fast click twice on View.

FeelGood
  • 5,594
  • 2
  • 25
  • 22
  • I tried few times as you said but I'm still not able to reproduce it.....still if thats the problem, can you tell me how to fix it – hArsh Jan 21 '16 at 11:54
  • In your case you might just remove OnClickListener during first processing: ```public void onClick(View v) { v.setOnClickListener(null); ... }``` – FeelGood Jan 21 '16 at 20:05
0

It looks like that you are trying to commit fragmentTransaction i.e. Replace Fragment, or Remove Fragment in one of onCreate(), onResume or onStart methods of Activity which is causing illlegaStateException

Mustansar Saeed
  • 2,730
  • 2
  • 22
  • 46
  • I'm just calling `onBackPressed()`. Actually I have a `Fragment` for showing image, which displays only when I double click on image. And I have also overrided the `onBackPressed()` of `Activity` to remove that fragment if `attached()` and if not calling the `super.onBackPressed()` So, I don't think I'm calling the `fragmentTransaction` in any of those – hArsh Jan 21 '16 at 12:03
  • This might be an issue that you are `committing fragment transaction` while the activity state is being changed. So try to remove fragment in other function according to your requirement. – Mustansar Saeed Jan 21 '16 at 12:06
0

This occurs when onBackPressed() is called after onSaveInstanceState() i.e when the mobile is locked and then onBackPressed() is called in background one hack is overide onSaveInstance() and in that add onBackPressed() in that method and it worked fine for me.

Spiker
  • 522
  • 4
  • 21