https://github.com/fanqieVip/keeplive
Integrated silent music (optimized power consumption), front desk service, dual-process guarding, pixel keep-alive, jobs five keep-alive methods
Mainstream Meizu, Xiaomi, Hammer, vivo, Nubia, Samsung, Huawei and other brands, the test results of models covering 4.4 to 9.0 are that as long as the user does not actively kill the program, it will not die, but some models lock the screen The problem of disconnection is not something I can solve.
How to use it, start the keep-alive service in the application
//Define the default style of the foreground service. I.e. title, description and icon ForegroundNotification foregroundNotification = new ForegroundNotification("测试","描述", R.mipmap.ic_launcher, //Define the notification click event of the foreground service new ForegroundNotificationClickListener() { @Override public void foregroundNotificationClick(Context context, Intent intent) { } }); //Start the keep-alive service KeepLive.startWork(this, KeepLive.RunMode.ENERGY, foregroundNotification, //You need keep-alive services, such as socket connections, timing tasks, etc. It is recommended not to write here in the way of anonymous internal classes new KeepLiveService() { /** * In operation * Since the service may be automatically started multiple times, this method may be called repeatedly */ @Override public void onWorking() { } /** * Termination of service * Since the service may be terminated multiple times, this method may be called repeatedly, and it needs to be used in conjunction with onWorking, such as registering and unregistering broadcast */ @Override public void onStop() { } } );
rely
Maven
<dependency> <groupId>com.fanjun</groupId> <artifactId>keeplive</artifactId> <version>1.1.20</version> <type>pom</type> </dependency>
Gradle
implementation 'com.fanjun:keeplive:1.1.20'
Precautions
Due to the use of dual-process daemon, you must ensure that the code in Application's onCreate is used in the main process when using this framework. Some users have some inexplicable problems, which is caused by this! ! !