All Projects → sunfusheng → Daemonservice

sunfusheng / Daemonservice

Android端心跳服务与进程保活

Programming Languages

java
68154 projects - #9 most used programming language

Labels

Projects that are alternatives of or similar to Daemonservice

voila-gpx-viewer
GPX Viewer web app built with Jupyter, ipywidgets, ipyleaflet, bqplot and voila
Stars: ✭ 43 (-83.71%)
Mutual labels:  binder
Bifrost
基于JSON PRC 协议的一种Android跨进程调用解决方案。
Stars: ✭ 24 (-90.91%)
Mutual labels:  binder
covid-19-community
Community effort to build a Neo4j Knowledge Graph (KG) that links heterogeneous data about COVID-19
Stars: ✭ 95 (-64.02%)
Mutual labels:  binder
nelua-decl
C binding generator for Nelua using GCC Lua plugin.
Stars: ✭ 30 (-88.64%)
Mutual labels:  binder
python-for-excel
This is the companion repo of the O'Reilly book "Python for Excel".
Stars: ✭ 253 (-4.17%)
Mutual labels:  binder
coronavirus-knowledge-graph
OBSOLETE: Prototype Neo4j Knowledge Graph for Coronavirus outbreaks (see NEW VERSION: https://github.com/covid-19-net/covid-19-community)
Stars: ✭ 17 (-93.56%)
Mutual labels:  binder
navo-workshop
Tutorial notebooks for how to use PyVO to access NASA and other data in Python.
Stars: ✭ 27 (-89.77%)
Mutual labels:  binder
binder-for-linux
An experimental project to port Android Binder IPC subsystem to Ubuntu Linux.
Stars: ✭ 110 (-58.33%)
Mutual labels:  binder
Binder
🦁"Hello World" <-> [🏷, 🏷, 🏷, 🏷]
Stars: ✭ 37 (-85.98%)
Mutual labels:  binder
examples
Example nteract notebooks with links to execution on mybinder.org
Stars: ✭ 24 (-90.91%)
Mutual labels:  binder
vscode-binder
VS Code on Binder
Stars: ✭ 88 (-66.67%)
Mutual labels:  binder
mybinder.org-deploy
Deployment config files for mybinder.org
Stars: ✭ 64 (-75.76%)
Mutual labels:  binder
openrefine-client
The OpenRefine Python Client from Paul Makepeace provides a library for communicating with an OpenRefine server. This fork extends the command line interface (CLI) and is distributed as a convenient one-file-executable (Windows, Linux, Mac). It is also available via Docker Hub, PyPI and Binder.
Stars: ✭ 67 (-74.62%)
Mutual labels:  binder
workshop
Workshop: Micromagnetics with Ubermag
Stars: ✭ 19 (-92.8%)
Mutual labels:  binder
clustergrammer2-notebooks
Examples using Clustergrammer2 to explore high-dimensional datasets.
Stars: ✭ 35 (-86.74%)
Mutual labels:  binder
appmode
Creating web applications with Jupyter and Binder
Stars: ✭ 37 (-85.98%)
Mutual labels:  binder
analisis-numerico-computo-cientifico
Análisis numérico y cómputo científico
Stars: ✭ 42 (-84.09%)
Mutual labels:  binder
libgbinder
GLib-style interface to binder
Stars: ✭ 21 (-92.05%)
Mutual labels:  binder
mmtf-workshop-2018
Structural Bioinformatics Training Workshop & Hackathon 2018
Stars: ✭ 50 (-81.06%)
Mutual labels:  binder
R-in-Jupyter-with-Binder
Example of how to use R in Jupyter notebooks and make compatible with Binder
Stars: ✭ 17 (-93.56%)
Mutual labels:  binder

DaemonService

Android端心跳服务与进程保活

使用

继承AbsHeartBeatService抽象心跳服务,在onHeartBeat()中处理自己的任务,具体保活策略不需要关心

public class HeartBeatService extends AbsHeartBeatService {

    @Override
    public void onStartService() {
    }

    @Override
    public void onStopService() {
    }

    @Override
    public long getHeartBeatMillis() {
        return 30 * 1000;
    }

    @Override
    public void onHeartBeat() {
    }
}

在Manifest中注册服务

<service android:name=".HeartBeatService"/>

初始化并启动服务

DaemonHolder.init(this, HeartBeatService.class);

实现思想

实现进程保活,暂时实现了双进程守护、JobService检测与拉起、进程死亡AlarmManager定时拉起、 广播监听(网络变化、开机等),同时通过Timer和TimerTask实现心跳服务。

1、双进程守护

双进程即本地进程和远程进程,看两个类: AbsHeartBeatService:本地进程,抽象的心跳服务 DaemonService:远程进程,即守护进程 启动本地服务后会启动远程进程的服务并绑定远程服务,同时远程服务也会绑定本地进程的服务, 任何一个服务停止都会得到另一个进程的Binder通知,即刻被拉起,实现进程保活的一种方式

2、JobService检测与拉起

Android5.0以上可以使用JobService来做定时任务,定时检测本地进程的服务是否在运行,参考JobSchedulerService, 但是个别深度定制的ROM厂商屏蔽了JobService,比如小米手机。

3、进程死亡AlarmManager定时拉起

AlarmManager是提供一种访问系统闹钟服务的方式,允许你去设置在将来的某个时间点去执行你的应用程序。 当你的闹钟时间到时,在它上面注册的一个意图(Intent)将会被系统以广播发出,然后自动启动目标程序,如果它没有正在运行。 所以,不管是我们的本地进程还是我们的远程进程,如果他们死了,就在死的时候定一个被拉活的闹钟,等待复活。

4、广播监听

动态广播监听:网络变化、开屏、锁屏、解锁、点击Home键
静态广播监听:开机、连接电源、断开电源、安装应用、卸载应用

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].