我有一个活动启动服务。服务崩溃'活动'的活动
在我的活动:
startService(new Intent(this, MyService.class));
在我的服务,在onStart():
/* 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);
的服务有一个计时器,做了一些工作,每3-4分钟,并以广播信息活动如果可能。当活动结束后,该服务应该继续工作。
当我运行该应用程序,并返回到主屏幕时,该服务继续运行。但过了一段时间我得到这些logcat的消息,并且该服务停止:
07-03 16:55:09.440:信息/ ActivityManager(583):进程com.myapp(PID 11665)已经死亡。 07-03 16:55:09.440:WARN/ActivityManager(583):坠毁服务com.myapp/.MyService的计划重启在5000毫秒
我如何避免这种情况?
好的,以及如何防止死亡的过程? – nhaarman