我這是網上下載一個文件在前臺前臺服務是當應用程序被殺害得到立即的Android 4.1〜5.1.1打死
@Override
public int onStartCommand(Intent intent, int flags, int sid){
this.sid = sid;
PendingIntent mainIntent = PendingIntent.getActivity(this, 0, MyApplication.mainIntent, 0);
Notification notification = new NotificationCompat.Builder(VuclipPrime.getInstance())
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Downloading Video")
.setContentText("Initiating...")
.setContentIntent(mainIntent)
.setAutoCancel(false)
.setOngoing(true)
.build();
startForeground(mNotificationId, notification);
if (VideoDownloadManager.currentVideoDownloadTask != null) {
VideoDownloadManager.currentVideoDownloadTask.start();
} else {
stopSelf();
}
return START_NOT_STICKY;
}
當我刷卡殺應用程序服務,該服務被也停下來。 我嘗試了所有StackOverflow上的現有解決方案,但都沒有工作。 我嘗試了YouTube應用程序,但並未終止其服務。我如何實現這一目標?謝謝。
21以上使用作業Sceduler api –