我得到了以下异常跟踪。
Fatal Exception: java.lang.RuntimeException: Unable to create application com.myapp.MyApplication: java.lang.SecurityException: Unable to start service Intent { cmp=com.myapp/.background.MyService }: Unable to launch app com.myapp/10232 for service Intent { cmp=com.myapp/.background.MyService }: user 0 is restricted
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688)
at android.app.ActivityThread.access$1600(ActivityThread.java:164)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1438)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5408)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
Caused by java.lang.SecurityException: Unable to start service Intent { cmp=com.myapp/.background.MyService }: Unable to launch app com.myapp/10232 for service Intent { cmp=com.myapp/.background.MyService }: user 0 is restricted
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1728)
at android.app.ContextImpl.startService(ContextImpl.java:1701)
at android.content.ContextWrapper.startService(ContextWrapper.java:516)
at com.myapp.MyApplication.onCreate(MyApplication.java:105)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4685)
at android.app.ActivityThread.access$1600(ActivityThread.java:164)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1438)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5408)
at java.lang.reflect.Method.invoke(Method.java)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
有关于这个例外的线索吗?看起来,应用程序是从访客用户安装的,并试图在管理员帐户中访问?我从OPPO R7 PLUS设备得到了这个例外。
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.myapp">
<application
android:name=".MyApplication"
android:allowBackup="false"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<service android:name=".background.MyService" />
</application>
</manifest>
请参阅OPPO的帖子:http://bbs.coloros.com/thread-174655-3-1.html
以下是该帖子的一些翻译:自动屏幕关闭一段时间后,系统将启动电池管理模块,禁止任何应用程序启动。但有一个错误,它应该强制停止应用程序,而不是抛出异常。
从开发者的角度来看,他们给出了一个解决方案:启动服务时使用"try-catch"。