Unity应用在前台,点击来自同一应用程序创建的通知时崩溃

3
我正在开发一款Unity应用。当应用在前台运行时,用户点击来自通知栏的通知视图并触发待处理意图时,应用会崩溃。在logcat中没有明确的堆栈跟踪可用,但可以看到应用程序崩溃时的情况如下:
I/WindowState: WIN DEATH: Window{26cb4ca u0 com.aman.unitytest/com.unity3d.player.UnityPlayerProxyActivity}
10-14 16:28:57.234 1796-2360/? 

当用户点击通知时,下面是logcat的片段:

10-14 16:28:56.359 3669-3669/? W/Timer-46: type=1400 audit(0.0:1190715): avc: denied { getattr } for uid=10230 path="/proc/194" dev="proc" ino=8077 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:r:kernel:s0 tclass=dir permissive=0
10-14 16:28:56.402 2404-2404/? D/StatusBar: Clicked on content of 0|com.aman.unitytest|10343|null|10231
10-14 16:28:56.410 1796-7655/? W/NotificationService: No notification with key: 0|com.aman.unitytest|10343|null|10231
--------- beginning of system
10-14 16:28:56.419 1796-1806/? I/ActivityManager: START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 pkg=com.aman.unitytest cmp=com.aman.unitytest/com.unity3d.player.UnityPlayerProxyActivity} from uid 10231 on display 0
10-14 16:28:56.435 2404-2404/? V/PhoneStatusBar: setLightsOn(true)
10-14 16:28:56.448 1796-10063/? W/InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@f50edaa attribute=null, token = android.os.BinderProxy@6095396
10-14 16:28:56.458 356-356/? I/SFPerfTracer:      triggers: (rate: 13:886) (compose: 0:2) (post: 0:1) (render: 1:49) (480:43276 frames) (481:45950)
10-14 16:28:56.459 356-356/? D/SFPerfTracer:        layers: (3:10) (FocusedStackFrame (0xb82131a0): 0:384)* (DimLayer (0xb8214f88): 0:23)* (StatusBar (0xb825eee8): 57:4149) (NavigationBar (0xb82b3180): 16:1944) (com.android.systemui.ImageWallpaper (0xb82a7ea0): 1:241)* (DimLayer (0xb82d3d08): 0:392)* (DimLayer (0xb8264580): 0:40)* (com.aman.unitytest/com.unity3d.player.UnityPlayerActivity (0xb8287078): 0:8)* (SurfaceView (0xb8288340): 479:4873) 
10-14 16:28:56.719 382-968/? W/APM::EffectDescriptor: unregisterEffect() unknown effect ID 354
10-14 16:28:56.839 1796-3013/? D/bsthal: setDelay, handle: 1598182229 delay: 200000000
10-14 16:28:56.839 1796-3013/? E/bsthal: <BST> set delay: 200000000ns
10-14 16:28:56.839 1796-3013/? I/bsthal: <BST> set delay of <BOSCH BMC150 Acceleration Sensor> to 200ms
10-14 16:28:56.861 1796-10063/? D/bsthal: activate, handle: 1598182242, enabled: 1, index 2
10-14 16:28:56.861 1796-10063/? D/bsthal: BstSensorExt: id=1598182242, en=1
10-14 16:28:56.861 1796-10063/? D/bsthal: enable ID_SORI, path /sys/class/srot_sensor/g_sensor/en_disp_rotation, fd 233
10-14 16:28:56.861 1796-2337/? D/bsthal: readEvents,event.type is 4,event value is -1,event code is 3
10-14 16:28:56.862 1796-2337/? D/bsthal: readEvents,event.type is 0,event value is 0,event code is 0
10-14 16:28:56.864 1796-10063/? D/bsthal: setDelay, handle: 1598182242 delay: 66667000
10-14 16:28:56.886 2404-2404/? V/PhoneStatusBar: setLightsOn(true)
10-14 16:28:56.900 2404-2404/? D/PhoneStatusBar: disable: < expand icons* alerts system_info* back home recent clock search quick_settings >
10-14 16:28:56.909 2404-2404/? V/QSTileView: setDual true
10-14 16:28:56.909 2404-2404/? V/QSTileView: setDual false
10-14 16:28:56.931 1796-1940/? I/LaunchCheckinHandler: Displayed com.aman.unitytest/com.unity3d.player.UnityPlayerProxyActivity,wp,wa,512
10-14 16:28:57.203 25990-25990/? I/Process: Sending signal. PID: 25990 SIG: 9
10-14 16:28:57.233 1796-7655/? I/WindowState: WIN DEATH: Window{26cb4ca u0 com.aman.unitytest/com.unity3d.player.UnityPlayerProxyActivity}
10-14 16:28:57.234 1796-2360/? D/WifiService: Client connection lost with reason: 4
10-14 16:28:57.238 1796-2833/? I/WindowState: WIN DEATH: Window{5747b17 u0 com.aman.unitytest/com.unity3d.player.UnityPlayerActivity}
10-14 16:28:57.281 1796-3017/? I/ActivityManager: Process com.aman.unitytest (pid 25990) has died
10-14 16:28:57.281 1796-3017/? W/ActivityManager: Scheduling restart of crashed service com.aman.unitytest/semusi.activitysdk.Api in 1000ms
10-14 16:28:57.282 1796-3017/? W/ActivityManager: Force removing ActivityRecord{38d66f8 u0 com.aman.unitytest/com.unity3d.player.UnityPlayerProxyActivity t994}: app died, no saved state
10-14 16:28:57.282 1796-3017/? I/ActivityManager: moveHomeStack, setupComplete:true
10-14 16:28:57.287 1796-3017/? D/bsthal: activate, handle: 1598182242, enabled: 0, index 2
10-14 16:28:57.287 1796-3017/? D/bsthal: BstSensorExt: id=1598182242, en=0
10-14 16:28:57.287 1796-3017/? D/bsthal: enable ID_SORI, path /sys/class/srot_sensor/g_sensor/en_disp_rotation, fd 103
10-14 16:28:57.313 25901-25938/? V/ConnectivityManager: isActiveNetworkMetered() returns:false

1
调试你的代码并检查崩溃的原因。仅通过检查日志我们无法提供帮助。 - Maveňツ
嗨,Maven,谢谢您的考虑。但是您能帮我解决如何调试Unity应用程序以检查导致上述问题的原因吗? - Aman Kumar Aggarwal
1个回答

1

我已经解决了问题并使其可行。以下是我现在为通知使用的pendingIntent。

launchIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_NEW_TASK);

当使用Unity时,AndroidManifest.xml中提到了一个已弃用的Launcher,请停止使用它。

com.unity3d.player.UnityPlayerProxyActivity

相反,使用以下条目在AndroidManifest中使其正确。

<activity
            android:name="com.unity3d.player.UnityPlayerActivity"
            android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"
            android:label="@string/app_name" >
             <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

由于ProxyActivity在其onCreate()方法中有以下内容,因此无论您在pendingIntent中添加什么标志都无关紧要。这个代理活动将忽略一切。
paramBundle = new String[] { "com.unity3d.player.UnityPlayerActivity", "com.unity3d.player.UnityPlayerNativeActivity" };
    copyPlayerPrefs(this, paramBundle);
    try
    {
      int i = Build.VERSION.SDK_INT >= 9 ? 1 : 0;
      paramBundle = Class.forName(paramBundle[0]);
      (paramBundle = new Intent(this, paramBundle)).addFlags(65536);
      Bundle localBundle;
      if ((localBundle = getIntent().getExtras()) != null) {
        paramBundle.putExtras(localBundle);
      }
      startActivity(paramBundle);
      return;
    }
    catch (ClassNotFoundException localClassNotFoundException) {}finally
    {
      finish();
    }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接