wince +sl 群

Scheduling restart of crashed service

    08-16 11:38:23.000: W/ActivityManager(389): Scheduling restart of crashed service

1. ActivityManager 与 service之间的关系

2. service正常关闭与异常关闭的情况

 

【http://www.cnblogs.com/wlrhnh/p/3529926.html】

如何提高Service的优先级避免被杀死或者杀死后如何再次重启Service?

我们知道,当进程长期不活动时,如果系统资源吃紧,会杀死一些Service,或不可见的Activity等所在的进程。 

如何避免Service被系统杀死,随便在网上搜一下,都能搜到好几种方法,但是每一种方法都有不同的适用环境。

1. 添加android:persistent="true"

添加android:persistent="true"到AndroidManifest.xml,Google文档描述如下:

Whether or not the application should remain running at all times-true" if it should, and "false"if not. The default value is "false". Applications should not normally set this flag; persistence mode is intended only for certain system applications.可见这个属性不能随便用,到目前为止,我所发现使用该属性的应用只有Phone,而且使用是要求权限的,所以这个属性对第三方应用来说意义不是很大;

2. 设置onStartCommand()的返回值

这个思路比较有用,我们着重分析一下,该方法有四种返回值:

 

TART_STICKY:kill后会被重启,但是重启后调用onStarfCommand()传进来的Intent参数为null,说明被kill的时候没有保存Intent;

START_NOT_STICKY:kill之后不会被重启;

 

posted @ 2016-08-16 13:40  pengxinglove  阅读(3556)  评论(0编辑  收藏  举报
wince +sl 群