我的前台服务在杀死应用程序后在某些设备(例如 vivo)上被杀死,有什么解决方法可以使其保持活动状态吗?
我正在使用前台服务,例如:
public class MyService extends IntentService {
private final String TAG = "IntentService";
private PowerManager.WakeLock wakeLock;
public MyService() {
super("MyService");
setIntentRedelivery(true);
}
@Override
protected void onHandleIntent(@Nullable Intent intent) {
Log.d(TAG, "onHandleIntent: Service running");
for (int i = 0; i < 20; i++) {
Log.d(TAG, "onHandleIntent: service running status: " + i);
SystemClock.sleep(3000);
}
}
@Override
public void onCreate() {
Log.d(TAG, "onCreate: IntentService Created");
super.onCreate();
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
this.wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"Service: WakeLock");
this.wakeLock.acquire();
Log.d(TAG, "onCreate: Wakelock …Run Code Online (Sandbox Code Playgroud) android background-service foregroundnotification foreground-service