在1.6 API中,有没有办法确保在服务因内存压力而被杀死后调用服务的onStart()方法?从日志中,似乎服务所属的“进程”重新启动,但服务本身不是。我在onStart()方法中放置了一个Log.d()调用,但是没有达到。
为了在内存压力下测试我的服务,我从一个活动中生成它,然后启动Web浏览器并访问一些Javascript密集的网站,如Slashdot,直到我的服务被杀死。 logcat读取:
03-07 16:44:13.778: INFO/ActivityManager(52): Process com.kostmo.charbuilder.full (pid 2909) has died.
03-07 16:44:13.778: WARN/ActivityManager(52): Scheduling restart of crashed service com.kostmo.charbuilder.full/com.kostmo.charbuilder.DownloadImagesService in 5000ms
03-07 16:44:13.778: INFO/ActivityManager(52): Low Memory: No more background processes.
03-07 16:44:13.778: ERROR/ActivityThread(52): Failed to find provider info for android.server.checkin
03-07 16:44:13.778: WARN/Checkin(52): Can't log event SYSTEM_SERVICE_LOOPING: java.lang.IllegalArgumentException: Unknown URL content://android.server.checkin/events
03-07 16:44:18.908: INFO/ActivityManager(52): Start proc com.kostmo.charbuilder.full for service com.kostmo.charbuilder.full/com.kostmo.charbuilder.DownloadImagesService: pid=3560 uid=10027 gids={3003, 1015}
03-07 16:44:19.868: DEBUG/ddm-heap(3560): Got feature list request
03-07 16:44:20.128: INFO/ActivityThread(3560): Publishing provider com.kostmo.charbuilder.full.provider.character: com.kostmo.charbuilder.provider.ImageFileContentProvider
答案 0 :(得分:6)
正如Chistopher上面的评论所揭示的那样,即使日志声称是“Scheduling restart of crashed service
”,这实际上并不意味着将调用onStart()
方法。但是,确实会调用onCreate()
,您的应用程序可以从那里调用onStart()
。