Unity-Technologies / com.unity.mobile.notifications

Mobile Notifications Package
https://docs.unity3d.com/Packages/com.unity.mobile.notifications@2.1/manual/index.html
Other
132 stars 42 forks source link

Mobile push notifications 2.1.0 AndroidJavaException: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState #236

Closed miguelfmlopes91 closed 1 year ago

miguelfmlopes91 commented 1 year ago

Hello I've recently upgraded my project to use the 2.1.0 version due to me able to request permission to the users and I've been getting some exceptions on some devices.

Unity Editor version : 2021.3..0f1 mobile.notifications version : 2.1.0

reproducibility: low, currently affects 0.458% of the live population.

devices: Mostly VIVO and OPPO devices. (low tier devices)

Stacktrace:

: AndroidJavaException: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState android.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1882) android.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1905) android.app.BackStackRecord.commitInternal(BackStackRecord.java:688) android.app.BackStackRecord.commit(BackStackRecord.java:646) com.unity3d.player.UnityPermissions.requestUserPermissions(Unknown Source:48) com.unity3d.player.UnityPlayer.nativeRender(Native Method) com.unity3d.player.UnityPlayer.access$300(Unknown Source:0) com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95) android.os.Handler.dispatchMessage(Handler.java:102) android.os.Looper.loop(Looper.java:257) com.unity3d.player.UnityPlayer$e.run(Unknown Source:20) UnityEngine.AndroidJNISafe.CheckException () (at <00000000000000000000000000000000>:0) UnityEngine.AndroidJavaObject._CallStatic (System.String methodName, System.Object[] args) (at <00000000000000000000000000000000>:0) X.Notifications.LocalNotifications.Android.AndroidNotificationsPlatform+d__22.MoveNext () (at <00000000000000000000000000000000>:0) UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <00000000000000000000000000000000>:0) X.Y.Start () (at <00000000000000000000000000000000>:0) X.Y:Start() I've created a CustomPermissionRequest class which derived from PermissionRequest as I wanted to have more granular control and serve it to devices below android 13 (with a custom intent). Could this be reasoning behind the crashes? Thanks for the reply, Miguel
aurimasc commented 1 year ago

What do you do on devices below android 13? You don't need to ask for notification permission there.

miguelfmlopes91 commented 1 year ago

On devices below android 13 I still ask as it's a design requirement.

aurimasc commented 1 year ago

On devices below android 13 I still ask as it's a design requirement.

What requirement? Do you have a requirement to ask for permission regardless of Android version? The stacktrace points to Unitys permission code. You should not get there on devices below android 13, as the notification permission is not recognized on those versions, Unity should report denied there.

aurimasc commented 1 year ago

Closing as no reply.

EgorLin commented 2 months ago

Hello. Same issue here, but it appears only on devices with android 13-14. We ask the permission as soon as possible on startup. Thanks for help Non-fatal Exception: java.lang.Exception: AndroidJavaException : java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState android.app.FragmentManagerImpl.checkStateLoss (android.app.FragmentManagerImpl) android.app.FragmentManagerImpl.enqueueAction (android.app.FragmentManagerImpl) android.app.BackStackRecord.commitInternal (android.app.BackStackRecord) android.app.BackStackRecord.commit (android.app.BackStackRecord) com.unity3d.player.UnityPermissions.requestUserPermissions (com.unity3d.player.UnityPermissions) com.unity3d.player.UnityPlayer.nativeRender (com.unity3d.player.UnityPlayer) com.unity3d.player.UnityPlayer.-$$Nest$mnativeRender (com.unity3d.player.UnityPlayer) com.unity3d.player.UnityPlayer$F$a.handleMessage (com.unity3d.player.UnityPlayer$F$a) android.os.Handler.dispatchMessage (android.os.Handler) android.os.Looper.loopOnce (android.os.Looper) android.os.Looper.loop (android.os.Looper) com.unity3d.player.UnityPlayer$F.run (com.unity3d.player.UnityPlayer$F) UnityEngine.AndroidJNISafe.CheckException (UnityEngine.AndroidJNISafe) UnityEngine.AndroidJavaObject._CallStatic (UnityEngine.AndroidJavaObject) Unity.Notifications.Android.PermissionRequest.RequestPermission (Unity.Notifications.Android.PermissionRequest) Unity.Notifications.Android.PermissionRequest..ctor (Unity.Notifications.Android.PermissionRequest.) App.Scripts.Modules.MobileNotifications.Data.AndroidNotificationsPlatform.RequestNotificationPermission (App.Scripts.Modules.MobileNotifications.Data.AndroidNotificationsPlatform)