서비스를 시작하는 활동이 있습니다. 내 서비스에서활동이 '사망'하면 서비스가 중단됩니다.
startService(new Intent(this, MyService.class));
, ONSTART() :
내 활동에서비스는 몇 가지 작업을 3 ~ 4 분 않는 타이머를 가지고
/* Show notification */
int icon = R.drawable.icon;
tickerText = getResources().getString(R.string.app_name);
long when = System.currentTimeMillis();
contentTitle = getResources().getString(R.string.app_name);
contentText = getResources().getString(R.string.running);
Intent notificationIntent = new Intent(this, activityClass).setAction(Intent.ACTION_MAIN).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
notification.flags = Notification.FLAG_ONGOING_EVENT;
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, notification);
startForeground(0, notification);
과에 방송 정보를 가능한 경우 활동. 활동이 종료되면 서비스는 계속 업무를 수행해야합니다.
앱을 실행하고 홈 화면으로 돌아 가면 서비스가 계속 실행됩니다. 그러나 잠시 후 나는이 로그 캣 메시지를 얻을하고 서비스를 중지 : 55 :
07-03 (16) 09.440 : INFO/ActivityManager (583) : 프로세스 com.myapp (PID 11665)이 사망했다. 07-03 16 : 55 : 09.440 : WARN/ActivityManager (583) : 나는이 문제를 방지하려면 어떻게
5000ms에서 추락 서비스 com.myapp/.MyService의 일정을 다시 시작?
좋아요, 그리고 어떻게 프로세스가 죽는 것을 방지 할 수 있습니까? – nhaarman