Log.d(TAG, "attachBaseContext")
// 定义前台通知的默认样式
val foregroundNotification = ForegroundNotification(
"标题", "描述", R.drawable.ic_small_notification
) { context, intent ->
// 定义前台服务的通知点击事件
}
KeepLive.useSilenceMusice(true)
//启动保活服务
KeepLive.startWork(this,
KeepLive.RunMode.ROGUE,
foregroundNotification,
object : KeepLiveService {
/**
* 运行中
* 由于服务可能会多次自动启动,该方法可能重复调用
*/
override fun onWorking() {
Thread anonymousThread = new Thread(new Runnable() {
@Override
public void run() {
int count = 0;
while(true){
count = count + 1;
Log.d(TAG, "run thread "+ count);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
});
anonymousThread.start();
}
/**
* 服务终止
* 由于服务可能会被多次终止,该方法可能重复调用,需同onWorking配套使用,如注册和注销broadcast
*/
override fun onStop() {
// do something
}
}
)
}