Android 防止service被kill

最近做的项目中,需要一直运行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);
	}

 

这样就能显示一个前台服务

猜你喜欢

转载自chenzheng8975.iteye.com/blog/2166636