Android 防止service被kill
程序员文章站
2022-06-04 15:36:44
...
最近做的项目中,需要一直运行service,可是,360一旦清理缓存就把我的service给kill掉了,在网上查了好多方法都不管用,最后终于找到一个:
private void initNotify() { Intent notificationIntent = new Intent(this, LockActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Notification notification = new Notification(); notification.setLatestEventInfo(this, "LockAppsService", "prevent service to be killed", pendingIntent); startForeground(1, notification); }
这样就能显示一个前台服务
上一篇: PHP,php教程
下一篇: 常太晚睡觉等于自杀!!熬夜也要有技巧!!