当前位置:   article > 正文

Android 中service 详解_activitymanager: unable to start service intent {

activitymanager: unable to start service intent { cmp=com.android.phone/.mod

上一次对于broadcast 的机制进行了详细的解析,见博文 android 中的 Broadcast 机制详解 ,本篇对于四大组件中的另一个成员—— service 进行解读。

 

在开发中我们会碰到下面几种情况:

1、java.lang.IllegalStateException: Not allowed to start service Intent

  1. 11-05 04:47:32.468 911 911 E AndroidRuntime: FATAL EXCEPTION: main
  2. 11-05 04:47:32.468 911 911 E AndroidRuntime: Process: com.shift.phonemanager, PID: 911
  3. 11-05 04:47:32.468 911 911 E AndroidRuntime: java.lang.RuntimeException: Unable to start receiver com.shift.phonemanager.apps.accesslog.PermissionAccessStartReceiver: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.shift.phonemanager/.apps.accesslog.service.PermissionAccessLogService }: app is in background uid UidRecord{a423648 u0a80 RCVR idle change:uncached procs:1 seq(0,0,0)}
  4. 11-05 04:47:32.468 911 911 E AndroidRuntime: at android.app.ActivityThread.handleReceiver(ActivityThread.java:3197)
  5. 11-05 04:47:32.468 911 911 E AndroidRuntime: at android.app.ActivityThread.-wrap17(Unknown Source:0)
  6. 11-05 04:47:32.468 911 911 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1675)
  7. 11-05 04:47:32.468 911 911 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
  8. 11-05 04:47:32.468 911 911 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164)
  9. 11-05 04:47:32.468 911 911 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6518)
  10. 11-05 04:47:32.468 911 911 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
  11. 11-05 04:47:32.468 911 911 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
  12. 11-05 04:47:32.468 911 911 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
  13. 11-05 04:47:32.468 911 911 E AndroidRuntime: Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { cmp=com.shift.phonemanager/.apps.accesslog.service.PermissionAccessLogService }: app is in background uid UidRecord{a423648 u0a80 RCVR idle change:uncached procs:1 seq(0,0,0)}
  14. 11-05 04:47:32.468 911 911 E AndroidRuntime: at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1521)
  15. 11-05 04:47:32.468 911 911 E AndroidRuntime: at android.app.ContextImpl.startService(ContextImpl.java:1477)
  16. 11-05 04:47:32.468 911 911 E AndroidRuntime: at android.content.ContextWrapper.startService(ContextWrapper.java:650)
  17. 11-05 04:47:32.468 911 911 E AndroidRuntime: at android.content.ContextWrapper.startService(ContextWrapper.java:650)
  18. 11-05 04:47:32.468 911 911 E AndroidRuntime: at com.shift.phonemanager.apps.accesslog.PermissionAccessStartReceiver.startAccessLogService(PermissionAccessStartReceiver.java:22)
  19. 11-05 04:47:32.468 911 911 E AndroidRuntime: at com.shift.phonemanager.apps.accesslog.PermissionAccessStartReceiver.onReceive(PermissionAccessStartReceiver.java:18)
  20. 11-05 04:47:32.468 911 911 E AndroidRuntime: at android.app.ActivityThread.handleReceiver(ActivityThread.java:3190)
  21. 11-05 04:47:32.468 911 911 E AndroidRuntime: ... 8 more

 

2、Bringing down service while still waiting for start foreground

11-05 01:47:21.268  1552  1570 W ActivityManager: Bringing down service while still waiting for start foreground: ServiceRecord{c1c6d87 u0 com.shift.phonemanager/.apps.accesslog.service.PermissionAccessLogService}

 

3、Context.startForegroundService() did not then call Service.startForeground()

  1. 11-05 01:47:21.506 1552 1570 E ActivityManager: ANR in .accesslog
  2. 11-05 01:47:21.506 1552 1570 E ActivityManager: PID: 2509
  3. 11-05 01:47:21.506 1552 1570 E ActivityManager: Reason: Context.startForegroundService() did not then call Service.startForeground()
  4. 11-05 01:47:21.506 1552 1570 E ActivityManager: Load: 0.0 / 0.0 / 0.0
  5. 11-05 01:47:21.506 1552 1570 E ActivityManager: CPU usage from 7022ms to 0ms ago (2007-11-05 01:47:14.249 to 2007-11-05 01:47:21.271):
  6. 11-05 01:47:21.506 1552 1570 E ActivityManager: 49% 1552/system_server: 24% user + 24% kernel / faults: 2576 minor
  7. 11-05 01:47:21.506 1552 1570 E ActivityManager: 19% 2306/android.process.media: 12% user + 6.6% kernel / faults: 5358 minor
  8. 11-05 01:47:21.506 1552 1570 E ActivityManager: 14% 1592/adbd: 3% user + 11% kernel / faults: 4277 minor
  9. 11-05 01:47:21.506 1552 1570 E ActivityManager: 13% 2207/com.android.launcher3: 11% user + 2.1% kernel / faults: 6393 minor
  10. 11-05 01:47:21.506 1552 1570 E ActivityManager: 9.1% 254/logd: 2.5% user + 6.5% kernel / faults: 30 minor
  11. 11-05 01:47:21.506 1552 1570 E ActivityManager: 7.1% 1472/zygote: 0.4% user + 6.7% kernel / faults: 3227 minor
  12. 11-05 01:47:21.506 1552 1570 E ActivityManager: 5.1% 1779/.dataservices: 3.8% user + 1.2% kernel / faults: 2197 minor
  13. 11-05 01:47:21.506 1552 1570 E ActivityManager: 5% 1805/com.android.phone: 2.2% user + 2.7% kernel / faults: 852 minor
  14. 11-05 01:47:21.506 1552 1570 E ActivityManager: 4.1% 1709/com.android.systemui: 3.7% user + 0.4% kernel / faults: 76 minor
  15. 11-05 01:47:21.506 1552 1570 E ActivityManager: 3.7% 518/logcat: 1.8% user + 1.8% kernel / faults: 5 minor
  16. 11-05 01:47:21.506 1552 1570 E ActivityManager: 3.4% 1470/surfaceflinger: 2.8% user + 0.5% kernel / faults: 160 minor
  17. ...
  18. ...

 

4、java.lang.SecurityException: Unable to start service

5、java.lang.SecurityException: Not allowed to start service

 

带着这么多的问题,有必要对于Android 中的service 进行剖析。将 AMS 中service 机制解析分以下几部分:

Android service 基础篇:

        Android基础总结之六:Sevice

Android service 启动篇:

        Android service 启动篇之 startService

        Android service 启动篇之 bindService

        Android service 启动篇之 startForegroundService

Android service 停止篇:

Android service 异常篇:

        java.lang.IllegalStateException: Not allowed to start service Intent

        Context.startForegroundService() did not then call Service.startForeground()

 

 

 

 

 

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/204051
推荐阅读
相关标签
  

闽ICP备14008679号