如果你有系统权限的话。
AndroidManifest.xml里
android:sharedUserId="android.uid.system"
<service android:name=".MainService" android:persistent="true" />
java文件件里:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Notification notification = new Notification.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(getText(R.string.app_name))
.build();
notification.flags |= Notification.FLAG_NO_CLEAR;
startForeground(1, notification);
return START_STICKY;
}
只是普通apk的话A和B双service互相保活: