yasirkula / UnityAndroidRuntimePermissions

A native Unity plugin to handle runtime permissions on Android M+
MIT License
196 stars 29 forks source link

IllegalStateException: Can not perform this action after onSaveInstanceState #15

Closed coffee-lady closed 1 year ago

coffee-lady commented 1 year ago

Description of the bug

Exception is thrown on some devices when trying invoke AndroidRuntimePermissions.RequestPermissionsAsync. I call CheckPermissions before request. I couldn't reproduce this, I see exceptions only in metrics.

Reproduction steps

If possible, providing reproduction steps would be very helpful while pinpointing the issue. You can also post screenshots if you think they would be helpful.

Platform specs

Please provide the following info if this is a Unity 3D repository.

Additional info

Message: AndroidJavaException: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
Exception: java.lang.Throwable: 
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
android.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1898)
android.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1921)
android.app.BackStackRecord.commitInternal(BackStackRecord.java:688)
android.app.BackStackRecord.commit(BackStackRecord.java:646)
com.yasirkula.unity.RuntimePermissions.RequestPermission(RuntimePermissions.java:112)
com.unity3d.player.UnityPlayer.nativeRender(Native Method)
com.unity3d.player.UnityPlayer.access$500(Unknown Source:0)
com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:126)
android.os.Handler.dispatchMessage(Handler.java:106)
android.os.Looper.loop(Looper.java:219)
com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
UnityEngine.AndroidJNISafe.CheckException ()
UnityEngine.AndroidJavaObject._CallStatic (System.String methodName, System.Object[] args)
AndroidRuntimePermissions.RequestPermissionsAsync (System.String[] permissions)
yasirkula commented 1 year ago

I have a fix for this but I wonder why this happens. Is your app a standard Unity app, Unity as a Library app, an app that can run in the background, or maybe something unique in another way?

coffee-lady commented 1 year ago

I have a fix for this but I wonder why this happens. Is your app a standard Unity app, Unity as a Library app, an app that can run in the background, or maybe something unique in another way?

It's just a game with Unity. I call permission check on app start.

yasirkula commented 1 year ago

I'm hoping that the latest release will resolve this issue.

coffee-lady commented 1 year ago

Thank you very much!