0

In my application, I have a viewpager inside and activity.

From one of the fragments, on a button click, I am firing an intent to view the dial box for making a call using intent.ACTION_VIEW

It works fine in most of the devices including 2.3.5, 4.0.8 and 4.1, but in LG Optimus 4.0.3 (L5) , it is asking the user to select among the Message and Call actions in a dialog. If I press the call button and then press back button, it works OK. But if I press back button without selecting any of the two, the app is crashing with the exception,

java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState

The same intent codes works fine in LG Optimus, if there is no fragments present.

I tried the fixes for similar error but they are not working.

I tried committing the fragment using commitAllowingStateLoss()

I also tried with this code in my activity's saveInstanceState

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState.putString("WORKAROUND_FOR_BUG_19917_KEY", "WORKAROUND_FOR_BUG_19917_VALUE");
        super.onSaveInstanceState(outState);
    }

Could anybody help me with this?

EDIT :

Error log:

    java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2448)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2476)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1177)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4476)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:816)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:583)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
    at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1299)
    at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:445)
    at android.support.v4.app.FragmentActivity.onBackPressed(FragmentActivity.java:164)
    at com.sample01.android.activity.ExtensionActivity.onBackPressed(ExtensionActivity.java:499)
    at com.sample01.android.activity.Main.onResume(MainActivity.java:328)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1156)
    at android.app.Activity.performResume(Activity.java:4710)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2438)
    ... 10 more
Aswathy P Krishnan
  • 11,728
  • 7
  • 27
  • 45

2 Answers2

0

I found a fix for this issue.

I tried checking for the exit status together with removing the super call in savedInstanceState.

super.onSaveInstanceState( savedInstanceState );

I was committing the fragments allowing state loss due to which my app was exiting.

I tried setting my app's EXIT STATUS as false.

Now it is checking for the exit status in the onBackpress() and it works fine!

Thanks to this POST which helped me in finding s solution.! Even the comments for that answer are helpful.

Community
  • 1
  • 1
Aswathy P Krishnan
  • 11,728
  • 7
  • 27
  • 45
0

if you have ProgressDialog stop it and add some test like : if ( progressDialog != null && progressDialog.isShowing()){ stopProgressBarDialog(); }

Badre
  • 710
  • 9
  • 17