다운로더 앱 프로젝트가 있고 다운로드 작업을 관리하고 다음과 같은 알림을 표시하기 위해 서비스 클래스를 사용하고 있습니다 : 문제 : 내가 닫을 때 최근 앱에서 스 와이프하여 앱을 중지하면 서비스가 중지됩니다. 하나의 서비스에 여러 알림이 있기 때문에 알림에
startForeground
을 사용할 수 없습니다. 그리고 나는 notify.setAutoCancel(true)
이 잘 작동하는 것을 좋아한다. 여기 멀티 태스킹 다운로더에 대한 백그라운드 서비스가 "최근 앱"의 닫기 앱일 때 중지
<service android:name=".Downloader" android:exported="false" android:enabled="true"
android:stopWithTask="false" />
서비스 시작 : 여기 는 AndroidManifest.xml에 코드
public static void intentDownload(Context context , FileInfo info) {
Intent intent = new Intent(context, Downloader.class);
intent.setAction(ACTION_DOWNLOAD);
intent.putExtra(EXTRA_TAG, info.Tag);
intent.putExtra(EXTRA_APP_INFO, info);
context.startService(intent);
}
여기 onStartCommand
입니다 :
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent != null) {
String action = intent.getAction();
FileInfo fInfo;
String tag = intent.getStringExtra(EXTRA_TAG);
switch (action) {
case ACTION_DOWNLOAD:
fInfo = (FileInfo) intent.getSerializableExtra(EXTRA_APP_INFO);
download(fInfo);
break;
case ACTION_PAUSE:
fInfo = (FileInfo) intent.getSerializableExtra(EXTRA_APP_INFO);
pause(fInfo);
break;
case ACTION_CANCEL:
cancel(tag);
break;
case ACTION_PAUSE_ALL:
pauseAll();
break;
case ACTION_CANCEL_ALL:
cancelAll();
break;
}
}
return Service.START_STICKY;
}
은 어떻게 그것을 해결할 수 있습니까?!
를 참조 사용 사망 후
서비스를 계속합니다. – SripadRaj@SripadRaj, 이렇게하면 다운로드 작업을 잃게됩니다. 서비스가 실행 중이고 작동 중입니다. –