android服务重启间隔,android – 崩溃的服务在很长一段时间后重新启动

com/android/server/am/ActiveServices.java(未曝光)

// How long we wait for a service to finish executing.

static final int SERVICE_TIMEOUT = 20*1000;

// How long a service needs to be running until restarting its process

// is no longer considered to be a relaunch of the service.

static final int SERVICE_RESTART_DURATION = 5*1000;

// How long a service needs to be running until it will start back at

// SERVICE_RESTART_DURATION after being killed.

static final int SERVICE_RESET_RUN_DURATION = 60*1000;

// Multiplying factor to increase restart duration time by, for each time

// a service is killed before it has run for SERVICE_RESET_RUN_DURATION.

static final int SERVICE_RESTART_DURATION_FACTOR = 4;

// The minimum amount of time between restarting services that we allow.

// That is, when multiple services are restarting, we won't allow each

// to restart less than this amount of time from the last one.

static final int SERVICE_MIN_RESTART_TIME_BETWEEN = 10*1000;

// Maximum amount of time for there to be no activity on a service before

// we consider it non-essential and allow its process to go on the

// LRU background list.

static final int MAX_SERVICE_INACTIVITY = 30*60*1000;

你发生的事情可能是你的服务比SERVICE_RESET_RUN_DURATION快死,然后重启时间乘以SERVICE_RESTART_DURATION_FACTOR.

从第881行开始:

// If it has been a "reasonably long time" since the service

// was started, then reset our restart duration back to

// the beginning, so we don't infinitely increase the duration

// on a service that just occasionally gets killed (which is

// a normal case, due to process being killed to reclaim memory).

if (now > (r.restartTime+resetTime)) {

r.restartCount = 1;

r.restartDelay = minDuration;

} else {

if ((r.serviceInfo.applicationInfo.flags

&ApplicationInfo.FLAG_PERSISTENT) != 0) {

// Services in peristent processes will restart much more

// quickly, since they are pretty important. (Think SystemUI).

r.restartDelay += minDuration/2;

} else {

r.restartDelay *= SERVICE_RESTART_DURATION_FACTOR;

if (r.restartDelay < minDuration) {

r.restartDelay = minDuration;

}

}

}

下面的行将支持您的服务.

r.restartDelay *= SERVICE_RESTART_DURATION_FACTOR;

因此,如果您的服务在运行SERVICE_RESET_RUN_DURATION之前死亡,您应该修复此案例.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值