代码拉取完成,页面将自动刷新
KeepAlive是在Leoric(通过JNI复活进程)的基础上,实现了通过ioctl复活进程,能最大程度提高复活率。
master
分支是利用 libbinder.so 与 ActivityManagerService 通信
的版本,ioctl
分支是使用 ioctl 与 binder 驱动通信
的版本。
注:
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
KeepAliveConfigs configs = new KeepAliveConfigs(
new KeepAliveConfigs.Config(getPackageName() + ":resident",
Service1.class.getCanonicalName()));
KeepAlive.init(base, configs);
}
<service
android:name="Service1"
android:process=":resident" />
Service需要继承KeepAliveService,否则在Android4.4上将没有保活效果。
startService(new Intent(MainActivity.this, Service1.class));
如果需要服务自启动,看第6条。
configs.ignoreBatteryOptimization();
// 配置短时间重启限制,每次重启间隔限制是10s,最多允许3次10秒内的连续重启
configs.rebootThreshold(10*1000, 3);
注:保活和重启限制相违背,更准确的应该做崩溃重启限制。
configs.setOnBootReceivedListener(new KeepAliveConfigs.OnBootReceivedListener() {
@Override
public void onReceive(Context context, Intent intent) {
// 设置服务自启
context.startService(new Intent(context, Service1.class));
}
});
下面是一种简单的方法杀死 KeepAlive:
ps -A | grep `ps -A | grep keepalive | awk '{print $1}' | head -1` | awk '{print $2}' | xargs kill -19 && am force-stop com.boolbird.keepalive
对于系统有两种思路可以选择:
项目根目录下的kill_alive.sh用于重复杀进程测试。
1、怎么保活多个进程 2、避免在Application中初始化第三方库,避免在所有进程都初始化第三方库
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。