Android Service保活模块(5.0以下使用c来fork进程,5.0以上使用JobService来保活进程)
1、在WorkService的onStartCommand中执行要保活的操作业务。
2、在初始化过程中调用KeepAliveManager.INSTANCE.startKeepAliveService(context);
3、停止服务调用KeepAliveManager.INSTANCE.stopKeepAliveSerice(context);
4、配置AndroidManifest.xml,增加如下配置:
<!--增加唤醒WorkService的定时任务-->
<service
android:name="jack.com.servicekeep.service.KeepAliveJobSchedulerService"
android:persistent="true"
android:exported="false"
android:permission="android.permission.BIND_JOB_SERVICE"
android:process="jack.com.servicekeep.job_scheduler_service"/>
<!--todo 自己业务保活的Service,替换android:name为自己的业务类-->
<service
android:name="jack.com.servicekeep.service.WorkService"
android:exported="true"
android:persistent="true"
android:label="Jack"
android:process="com.jack.workservice">
</service>
<!--开机启动监听-->
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />