服务 进程守护 MarsDaemon 简介

MarsDaemon 基本功能

It is a lite library, you can make your project depend it easily, and your project will be UNDEAD不会被杀死.

support to keep alive from Android_API 9 to Android_API 23
support to keep alive in most of devices各种机型(contains Sumsung\Huawei\Meizu\Mi\Nexus..)
support to keep alive in FORCE_CLOSE强制关闭 from SystemSettings系统设置 and MEMORY_CLEAN内存清理 from third-part第三方清理工具 apps (such like CleanMaster\360 and so on)
support to keep BOOT_RECEIVER完美自启动 work well simplely

Version  1.0

Installation 使用步骤

STEP1

make your project depend on LibMarsdaemon, and regist 2 Service and 2 BroadcastReceiver in your manifests in 2 different process.
 
    
  1. <service android:name=".Service1" android:process=":process1"/>
  2. <receiver android:name=".Receiver1" android:process=":process1"/>
  3. <service android:name=".Service2" android:process=":process2"/>
  4. <receiver android:name=".Receiver2" android:process=":process2"/>
Service1 is the Service which you want to be undead, you can do somethings in it.
But the others is used by Marsdaemon, so DONNOT do anything inside.

STEP2

make your application extends DaemonApplication and override the method getDaemonConfigurations(). Return back the confugirations.

 
    
  1. @Override
  2. protected DaemonConfigurations getDaemonConfigurations() {
  3.     DaemonConfigurations.DaemonConfiguration configuration1 = new DaemonConfigurations.DaemonConfiguration("com.marswin89.marsdaemon.demo:process1", Service1.class.getCanonicalName(), Receiver1.class.getCanonicalName());
  4.     DaemonConfigurations.DaemonConfiguration configuration2 = new DaemonConfigurations.DaemonConfiguration("com.marswin89.marsdaemon.demo:process2", Service2.class.getCanonicalName(), Receiver2.class.getCanonicalName());
  5.     DaemonConfigurations.DaemonListener listener = new MyDaemonListener();
  6.     //return new DaemonConfigurations(configuration1, configuration2);//listener can be null
  7.     return new DaemonConfigurations(configuration1, configuration2, listener);
  8. }

if you want to override attachBaseContext you will find it had been defined final by me. you can override attachBaseContextByDaemon instead it.

see more details in MyApplication1 in Demo

if your application has extends another application, you should create a DaemonClient and perfrom it in attachBaseContext(), DONOT forget perform super.attachBaseContext() before!

 
    
  1. private DaemonClient mDaemonClient;
  2. @Override
  3. protected void attachBaseContext(Context base) {
  4.     super.attachBaseContext(base);
  5.     mDaemonClient = new DaemonClient(createDaemonConfigurations());
  6.     mDaemonClient.onAttachBaseContext(base);
  7. }

see more details in MyApplication2 in DemoMarsdaemon

STEP3

Launch the Service once, and try to kill it.

相关分析文章

这是一个轻量级的库,配置几行代码,就可以实现在Android上实现进程常驻,也就是在系统强杀下,以及360获取root权限下,clean master获取root权限下都无法杀死进程
支持系统2.3到6.0
支持大部分设备,包括三星,华为,oppo,nexus,魅族等等
可以简单对开机广播进行保护

github地址:

原理分析:

转载于:https://www.cnblogs.com/baiqiantao/p/6375739.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值