MvvmCross / MvvmCross-AndroidSupport

Android support library packages for MvvmCross: The .NET MVVM framework for cross-platform solutions.
http://mvvmcross.com
15 stars 0 forks source link

Java.Lang.IllegalStateExceptionCan not perform this action after onSaveInstanceState #283

Closed flaviusdemian closed 8 years ago

flaviusdemian commented 8 years ago

Steps to reproduce

  1. Navigate from MvxCachingFragmentActivity A to MvxAppCompatActivity B and then to MvxAppCompatActivity C
  2. The first on back press always works
  3. the second one never works and always throwns IllegalStateException

    Expected behavior

It should close Activity B and open Activity A which has a viewpager with 2 fragments.

Actual behavior

Java.Lang.IllegalStateExceptionCan not perform this action after onSaveInstanceState
Raw
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x9adfbe18 + 0x00024> in <filename unknown>:0 
  at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (JniObjectReference instance, JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) <0x9b195ca8 + 0x000d3> in <filename unknown>:0 
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) <0x9b059288 + 0x00133> in <filename unknown>:0 
  at Android.App.Activity.OnBackPressed () <0x98845ff8 + 0x00043> in <filename unknown>:0 
  at MvvmCross.Droid.Support.V4.MvxCachingFragmentActivity.OnBackPressed () <0x98845e38 + 0x000af> in <filename unknown>:0 
  at UpWorky.Mobile.Android.Employer.UI.Activities.EmployeeProfileActivity.OnBackPressedAction () <0x9a3fe230 + 0x0001f> in <filename unknown>:0 
  at UpWorky.Mobile.Android.Common.Services.ToolbarNavigationService.OnBackPressed () <0x98845d78 + 0x0003f> in <filename unknown>:0 
  at UpWorky.Core.Common.ViewModels.BaseViewModel+<>c.<get_BackCommand>b__6_0 () <0x98845d20 + 0x00033> in <filename unknown>:0 
  at MvvmCross.Core.ViewModels.MvxCommand.Execute (System.Object parameter) <0x99428248 + 0x0003b> in <filename unknown>:0 
  at MvvmCross.Binding.Droid.Target.MvxViewClickBinding.ViewOnClick (System.Object sender, System.EventArgs args) <0x994281d8 + 0x00067> in <filename unknown>:0 
  at Android.Views.View+IOnClickListenerImplementor.OnClick (Android.Views.View v) <0x99428180 + 0x0003f> in <filename unknown>:0 
  at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (IntPtr jnienv, IntPtr native__this, IntPtr native_v) <0x994280e0 + 0x00063> in <filename unknown>:0 
  at (wrapper dynamic-method) System.Object:9ea002e0-b6e0-4abc-a0a8-ab27a35e4873 (intptr,intptr,intptr)
  --- End of managed exception stack trace ---
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
    at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1493)
    at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(FragmentManager.java:584)
    at android.support.v4.app.FragmentActivity.onBackPressed(FragmentActivity.java:188)
    at mono.android.view.View_OnClickListenerImplementor.n_onClick(Native Method)
    at mono.android.view.View_OnClickListenerImplementor.onClick(View_OnClickListenerImplementor.java:30)
    at android.view.View.performClick(View.java:5204)
    at android.view.View$PerformClick.run(View.java:21153)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:5417)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
InnerStackTraces[0]Java.Interop.JniEnvironment

Configuration

MvvmCrossVersion:

<package id="MvvmCross" version="4.2.2" targetFramework="monoandroid6.0.99" />

mvvmcrossbug

Android Support V4 version :

<package id="Xamarin.Android.Support.v4" version="23.4.0.1" targetFramework="monoandroid6.0.99" />
flaviusdemian commented 8 years ago

I have to mention that this works perfectly if I just do one level navigation back and forth from the FragmentActivity to the Activities...It happens only when we have more than 1 navigation level. Most probably the stack of fragments generates the problem

andreinitescu commented 8 years ago

not sure if this is the case, but this error Java.Lang.IllegalStateExceptionCan not perform this action after onSaveInstanceState usually means a fragment transaction is run when activity save state was already run, something shouldn't happen because it means fragment transaction is lost and sometimes this happens when doing asynchronous fragment navigation I don't think this helps at all... Have you tried to debug it a bit with the source code? Any luck?

flaviusdemian commented 8 years ago

Hello Andrei,

I have changed everywhere to commitAllowingStateLoss and it did not help. I don't have anything async there. I will provide tomorrow a small demo in which it breaks.

Flavius

andreinitescu commented 8 years ago

Salut Flavius, to "fix" the erorr maybe you could catch the exception, but note that fragment transaction won't be saved. ideally you need to figure out what triggers this situation and fix it

andreinitescu commented 8 years ago

by the way, for now, why don't you only use MvxAppCompatActivity?

flaviusdemian commented 8 years ago

For the drawer I need to use a FragmentActivity. Besides this, I use MvxAppCompatActivity.

andreinitescu commented 8 years ago

Not sure, but try with MvxCachingFragmentCompatActivity

flaviusdemian commented 8 years ago

I will. Normally it is not needed. I will let you know how it worked. Mersi

flaviusdemian commented 8 years ago

I think we have nailed it...It was something we did. We had an action hooked from another fragment which was already disposed. We still have one scenario. I will get back to you if it's now fixed.

Thank you for your info.