Bug 46436 - [Android] IllegalStateException thrown when pushing a new page after picking a photo from the library using Media Plugin
Summary: [Android] IllegalStateException thrown when pushing a new page after picking ...
Status: RESOLVED DUPLICATE of bug 47367
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-11-03 21:50 UTC by Jon Goldberger [MSFT]
Modified: 2017-02-27 17:58 UTC (History)
3 users (show)

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


Attachments
Test Project (53.61 KB, application/zip)
2016-11-03 21:50 UTC, Jon Goldberger [MSFT]
Details


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 DUPLICATE of bug 47367

Description Jon Goldberger [MSFT] 2016-11-03 21:50:46 UTC
Created attachment 18321 [details]
Test Project

## Description

IllegalStateException thrown when pushing a new page after picking a photo from the library using Media Plugin on Android (works fine on iOS). The exception does not occur every time, but mostly it does, so it would seem to be some race condition. Stack Trace:

>Java.Lang.IllegalStateException: Can not perform this action after onSaveInstanceState
>  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
>  at Java.Interop.JniEnvironment+InstanceMethods.CallIntMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method) [0x00084] in /Users/builder/data/lanes/3819/96c7ba6c/source/Java.Interop/src/Java.Interop/Java.Interop/JniEnvironment.g.cs:11464
>  at Android.Runtime.JNIEnv.CallIntMethod (System.IntPtr jobject, System.IntPtr jmethod) [0x00000] in /Users/builder/data/lanes/3819/96c7ba6c/source/monodroid/src/Mono.Android/JNIEnv.g.cs:186
>  at Android.Support.V4.App.FragmentTransactionInvoker.Commit () [0x00033] in <27c17fe440cf491ba8255bcefade6e02>:0
>  at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.SwitchContentAsync (Xamarin.Forms.Page view, System.Boolean animated, System.Boolean removed, System.Boolean popToRoot) [0x0014b] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:620
>  at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnPushAsync (Xamarin.Forms.Page view, System.Boolean animated) [0x00000] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:451
>  at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.PushViewAsync (Xamarin.Forms.Page page, System.Boolean animated) [0x00000] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:108
>  at Xamarin.Forms.Platform.Android.AppCompat.NavigationPageRenderer.OnPushed (System.Object sender, Xamarin.Forms.Internals.NavigationRequestedEventArgs e) [0x00000] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\NavigationPageRenderer.cs:456
>  at Xamarin.Forms.NavigationPage+<PushAsyncInner>d__90.MoveNext () [0x0006a] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Core\NavigationPage.cs:355
>  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
>  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
>  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
>  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
>  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113
>  at Xamarin.Forms.NavigationPage+<PushAsync>d__48.MoveNext () [0x0017f] in C:\BuildAgent2\work\aad494dc9bc9783\Xamarin.Forms.Core\NavigationPage.cs:180
>  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
>  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
>  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
>  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
>  at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113
>  at TestMediaPlugin.MyPage+<HandleAction>c__async0.MoveNext () [0x00159] in /Users/jongoldberger/Downloads/TestMediaPlugin/TestMediaPlugin/TestMediaPlugin.cs:94
>  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143
>  at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (System.Object state) [0x00000] in /Users/builder/data/lanes/3819/96c7ba6c/source/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018
>  at Android.App.SyncContext+<Post>c__AnonStorey0.<>m__0 () [0x00000] in /Users/builder/data/lanes/3819/96c7ba6c/source/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:18
>  at Java.Lang.Thread+RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/3819/96c7ba6c/source/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36
>  at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in /Users/builder/data/lanes/3819/96c7ba6c/source/monodroid/src/Mono.Android/platforms/android-24/src/generated/Java.Lang.IRunnable.cs:81
>  at at (wrapper dynamic-method) System.Object:2807f955-7c76-4ea6-985c-8d7961ca813c (intptr,intptr)
>  at java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
>  at at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1493)
>  at at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1511)
>  at at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:638)
>  at at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:617)
>  at at mono.java.lang.RunnableImplementor.n_run(Native Method)
>  at at mono.java.lang.RunnableImplementor.run(RunnableImplementor.java:30)
>  at at android.os.Handler.handleCallback(Handler.java:739)
>  at at android.os.Handler.dispatchMessage(Handler.java:95)
>  at at android.os.Looper.loop(Looper.java:148)
>  at at android.app.ActivityThread.main(ActivityThread.java:5417)
>  at at java.lang.reflect.Method.invoke(Native Method)
>  at at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
>  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)


## Steps to reproduce:

1. Open the attached test project and deploy Android project to device or simulator (Tested on Google HAXM emulator running Marshmallow)

2. If there are no photos in your device's library, take a photo so a photo will be in the gallery. 

3. Click the "Select Photo" button.

4. Choose a photo.

Expected result: A new page with the selected photo shown will be pushed.

Actual result: IllegalStateException (try again if at first you don't get this)

## Notes

It seems that introducing a short delay resolves this issue. So right before pushing the new page, add:
> await System.Threading.Tasks.Task.Delay(10);

May be related to bug #36907?


## Environment

=== Xamarin Studio Enterprise ===

Version 6.1.1 (build 17)
Installation UUID: ceaba76c-db06-4fbd-b326-f69ea53c3e01
Runtime:
	Mono 4.6.1 (mono-4.6.0-branch-c8sr0/ef43c15) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406010005

=== NuGet ===

Version: 3.4.3.0

=== Xamarin.Profiler ===

Version: 0.33.1
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin.Android ===

Version: 7.0.1.3 (Visual Studio Enterprise)
Android SDK: /Users/jongoldberger/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)
		7.0   (API level 24)

SDK Tools Version: 25.2.2
SDK Platform Tools Version: 24.0.3
SDK Build Tools Version: 24.0.3

Java SDK: /usr
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Xamarin Inspector ===

Version: 0.10.0.0
Hash: e931a52
Branch: master
Build date: Thu, 18 Aug 2016 17:46:46 GMT

=== Apple Developer Tools ===

Xcode 8.1 (11544)
Build 8B62

=== Xamarin.iOS ===

Version: 10.2.0.4 (Visual Studio Enterprise)
Hash: b638977
Branch: xcode8.1
Build date: 2016-10-25 14:38:48-0400

=== Xamarin.Mac ===

Version: 2.10.0.105 (Visual Studio Enterprise)

=== Build Information ===

Release ID: 601010017
Git revision: 44d481a9be9cf2bf7c01bfb99c59b77dfa08e712
Build date: 2016-10-25 14:27:24-04
Xamarin addins: 19cdb28081bf28d9688698030abb96e04e391f69
Build lane: monodevelop-lion-cycle8-sr0

=== Operating System ===

Mac OS X 10.12.1
Darwin Jons-MacBook-Pro.local 16.1.0 Darwin Kernel Version 16.1.0
    Thu Oct 13 21:26:57 PDT 2016
    root:xnu-3789.21.3~60/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Xamarin Inspector 0.10.0.0
Comment 1 adrianknight89 2016-11-24 20:32:40 UTC
Ref https://github.com/xamarin/Xamarin.Forms/pull/527
Comment 3 Jimmy [MSFT] 2017-02-27 17:58:33 UTC

*** This bug has been marked as a duplicate of bug 47367 ***