xamarin boot_completed崩溃了android 8+

时间:2018-08-24 12:51:36

标签: android xamarin xamarin.android

我当前正在开发一个Android应用程序,并且在Android 8到9上有一个神秘的问题。当我重新启动手机时,我收到一条警告消息,警告我该应用程序失败(主要是因为在Boot_Completed ),但应用程序的服务仍可正常运行。通过堆栈跟踪,我可以说问题出在启动任何其他服务的广播接收器上。

很遗憾,我无法找到解决该问题的方法。

下面,您可以看到我的广播接收器。

[BroadcastReceiver( Name = "com.parroinfo.SERVICE_STARTUP", Enabled = true, Exported = true, DirectBootAware = true)]
    [IntentFilter(new[] {Intent.ActionBootCompleted, Intent.ActionLockedBootCompleted}, Priority = (int)IntentFilterPriority.HighPriority)]
    class ServiceStartup : BroadcastReceiver
    {
        public override void OnReceive(Context context, Intent intent)
            {
             if (AndroidUtils.isVersionBelow(BuildVersionCodes.O))
             {
                        context.StartService(new Intent(context, -type-));
                     }
                     else
                     {
                        context.StartForegroundService(new Intent(context, -type-));
                     }
        }
    }

下面,您可以在清单上看到我的声明。

<receiver android:exported="true" android:name="com.parroinfo.SERVICE_STARTUP">
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
</receiver>

下面,您可以看到问题的堆栈跟踪。

java.lang.RuntimeException: 
at android.app.ActivityThread.handleReceiver (ActivityThread.java:3388)
at android.app.ActivityThread.access$1200 (ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1661)
at android.os.Handler.dispatchMessage (Handler.java:106)
at android.os.Looper.loop (Looper.java:193)
at android.app.ActivityThread.main (ActivityThread.java:6669)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run  
(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:858)
Caused by: java.lang.IllegalStateException: 
at android.app.ContextImpl.startServiceCommon (ContextImpl.java:1577)
at android.app.ContextImpl.startService (ContextImpl.java:1532)
at android.content.ContextWrapper.startService (ContextWrapper.java:664)
at com.parroinfo.SERVICE_STARTUP.n_onReceive (Native Method)
at com.parroinfo.SERVICE_STARTUP.onReceive (SERVICE_STARTUP.java:29)
at android.app.ActivityThread.handleReceiver (ActivityThread.java:3379)

1 个答案:

答案 0 :(得分:0)

我终于解决了我的问题。该问题是由Firebase引起的,后者进行了更新,因此避免设置启动完成的服务。所以我的解决办法是不要从棉花糖启动任何Android版本的服务。