Bug 38596 - Java.Lang.IllegalStateExceptionActivity has been destroyed in OnDestroy()
Summary: Java.Lang.IllegalStateExceptionActivity has been destroyed in OnDestroy()
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.0.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Paul DiPietro [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2016-02-09 20:10 UTC by Caan Mee
Modified: 2017-06-19 17:44 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Caan Mee 2016-02-09 20:10:27 UTC
Hello I'm experiencing the following exception on low-end devices when clicking on a local notification which launches an intent to resume the application:

var intend = Application.Context.PackageManager.GetLaunchIntentForPackage(Application.Context.PackageName);
intend.SetFlags(ActivityFlags.ClearTask | ActivityFlags.ClearTop);
PendingIntent.GetActivity(Application.Context, 0, intend, PendingIntentFlags.UpdateCurrent);


Java.Lang.IllegalStateExceptionActivity has been destroyed
Raw
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x68275298 + 0x00024> in <filename unknown>:0 
  at Android.Runtime.JNIEnv.CallIntMethod (IntPtr jobject, IntPtr jmethod) <0x64568090 + 0x000ab> in <filename unknown>:0 
  at Android.Support.V4.App.FragmentTransactionInvoker.CommitAllowingStateLoss () <0x68274490 + 0x00073> in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.Dispose (Boolean disposing) <0x682739d0 + 0x00137> in <filename unknown>:0 
  at Java.Lang.Object.Dispose () <0x648fc0c8 + 0x0001f> in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.MasterDetailContainer.DisposeChildRenderers () <0x68273918 + 0x0003b> in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.MasterDetailContainer.Dispose (Boolean disposing) <0x682738d0 + 0x00033> in <filename unknown>:0 
  at Java.Lang.Object.Dispose () <0x648fc0c8 + 0x0001f> in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer.Dispose (Boolean disposing) <0x682732a8 + 0x0006f> in <filename unknown>:0 
  at Java.Lang.Object.Dispose () <0x648fc0c8 + 0x0001f> in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) <0x64ebd740 + 0x00103> in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.AppCompat.Platform.Dispose () <0x68272398 + 0x0002b> in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnDestroy () <0x6825ec70 + 0x0006f> in <filename unknown>:0 
  at Android.App.Activity.n_OnDestroy (IntPtr jnienv, IntPtr native__this) <0x6826ef10 + 0x00037> in <filename unknown>:0 
  at (wrapper dynamic-method) System.Object:9b0c1a49-2799-4fb3-ad48-a2dce8686f72 (intptr,intptr)
  --- End of managed exception stack trace ---
java.lang.IllegalStateException: Activity has been destroyed
	at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1470)
	at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:634)
	at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:617)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.n_onDestroy(Native Method)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.onDestroy(FormsAppCompatActivity.java:70)
	at android.app.Activity.performDestroy(Activity.java:5211)
	at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1124)
	at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3306)
	at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3337)
	at android.app.ActivityThread.access$1300(ActivityThread.java:134)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loop(Looper.java:137)
	at android.app.ActivityThread.main(ActivityThread.java:4867)
	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:1007)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
	at dalvik.system.NativeStart.main(Native Method)


Using Xamarin.Forms 2.1.0-pre4
Android: 4.1.2
Comment 1 Caan Mee 2016-02-16 11:07:40 UTC
Now I also found These issues to appear on a Nexus 5 running Android 6.0 with Forms 2.1.0-pre4.

Java.Lang.RuntimeExceptionActivity has been destroyed
Raw
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <filename unknown>:0 
  at Android.Runtime.JNIEnv.CallIntMethod (IntPtr jobject, IntPtr jmethod) [0x00069] in <filename unknown>:0 
  at Android.Support.V4.App.FragmentTransactionInvoker.CommitAllowingStateLoss () [0x00033] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.Dispose (Boolean disposing) [0x00067] in <filename unknown>:0 
  at Java.Lang.Object.Dispose () [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.MasterDetailContainer.DisposeChildRenderers () [0x0000f] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.MasterDetailContainer.Dispose (Boolean disposing) [0x00009] in <filename unknown>:0 
  at Java.Lang.Object.Dispose () [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.AppCompat.MasterDetailPageRenderer.Dispose (Boolean disposing) [0x0003a] in <filename unknown>:0 
  at Java.Lang.Object.Dispose () [0x00000] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x0003f] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.AppCompat.Platform.Dispose () [0x00010] in <filename unknown>:0 
  at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnDestroy () [0x0002f] in <filename unknown>:0 
  at Android.App.Activity.n_OnDestroy (IntPtr jnienv, IntPtr native__this) [0x00009] in <filename unknown>:0 
  at (wrapper dynamic-method) System.Object:687e42eb-df25-4587-91fb-64e3074b5826 (intptr,intptr)
  --- End of managed exception stack trace ---
java.lang.IllegalStateException: Activity has been destroyed
	at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1470)
	at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:634)
	at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:617)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.n_onDestroy(Native Method)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.onDestroy(FormsAppCompatActivity.java:70)
	at android.app.Activity.performDestroy(Activity.java:6407)
	at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1142)
	at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3818)
	at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3849)
	at android.app.ActivityThread.-wrap5(ActivityThread.java)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	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)
Comment 2 Akash Kava 2016-12-19 12:28:16 UTC
Every time an app is closed with back button, this appears.....

Is anybody serious about taking look at this error at all?


Unhandled Exception:
Java.Lang.IllegalStateException: Activity has been destroyed
  --- End of managed Java.Lang.IllegalStateException stack trace ---
java.lang.IllegalStateException: Activity has been destroyed
	at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1515)
	at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:638)
	at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:621)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.n_onDestroy(Native Method)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.onDestroy(FormsAppCompatActivity.java:80)
	at android.app.Activity.performDestroy(Activity.java:5403)
	at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1117)
	at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3470)
	at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3501)
	at android.app.ActivityThread.access$1400(ActivityThread.java:135)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1249)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:136)
	at android.app.ActivityThread.main(ActivityThread.java:5001)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:515)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
	at dalvik.system.NativeStart.main(Native Method)
[ERROR] FATAL UNHANDLED EXCEPTION: Java.Lang.IllegalStateException: Activity has been destroyed
  --- End of managed Java.Lang.IllegalStateException stack trace ---
java.lang.IllegalStateException: Activity has been destroyed
	at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1515)
	at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:638)
	at android.support.v4.app.BackStackRecord.commitAllowingStateLoss(BackStackRecord.java:621)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.n_onDestroy(Native Method)
	at md5b60ffeb829f638581ab2bb9b1a7f4f3f.FormsAppCompatActivity.onDestroy(FormsAppCompatActivity.java:80)
	at android.app.Activity.performDestroy(Activity.java:5403)
	at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1117)
	at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3470)
	at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3501)
	at android.app.ActivityThread.access$1400(ActivityThread.java:135)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1249)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:136)
	at android.app.ActivityThread.main(ActivityThread.java:5001)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:515)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
	at dalvik.system.NativeStart.main(Native Method)
Comment 3 Paul DiPietro [MSFT] 2016-12-21 15:41:36 UTC
Hello -- unfortunately we can't do much to help here without a reproduction (preferably as minimal as possible with steps to reproduce the issue), as a stack trace alone doesn't tell us very much.
Comment 4 Sylvain Gravel 2016-12-28 22:19:37 UTC
Having the same issue as Akash.  everything was working fine with the regular Forms Activity but this started when I switched to the Forms AppCompat Activity.  On a API 21 device I get something very similar when loading a YouTube player fragment...

Sorry but I don't have time to isolate the problem in a project at the moment.
Comment 5 Akash Kava 2016-12-29 07:55:39 UTC
@Paul

Please have a look at this Sample,

https://github.com/neurospeech/xamarin-ui-atoms-samples

Also note, the exception is caught and logged in debugger, this solves crash, but you will get an idea of why it is causing.
Comment 6 Akash Kava 2016-12-29 07:59:14 UTC
The exception comes when you keep pressing back button after navigating to some of the page in menu.
Comment 7 Sylvain Gravel 2016-12-29 12:42:28 UTC
My problem was a duplicate of this : https://bugzilla.xamarin.com/show_bug.cgi?id=46494
Comment 8 Chris King 2017-06-19 17:21:56 UTC
Assigned to you as you were last to request additional info.
Comment 9 Paul DiPietro [MSFT] 2017-06-19 17:44:45 UTC
This issue will be closed as the referred to issue appears to have been resolved and we could believe it to no longer be an issue. Please reopen this and attach a minimized reproduction project if the issue still exists as of the latest prerelease or nightly build; you are also welcome to redirect to that other issue if you feel it is more appropriate.

Thanks!