我开发了一个应用程序(称为即时按钮),该应用程序具有小部件功能。此小部件使用PendingIntent作为小部件的onClick。Wndingget中的PendingIntent + TaskKiller
我的PendingIntent的代码是这样的:
Intent active = new Intent(context, InstantWidget.class);
active.setAction(String.valueOf(appWidgetId));
active.putExtra("blabla", blabla); //Some data
PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
actionPendingIntent.cancel();
actionPendingIntent = PendingIntent.getBroadcast(context, 0, active, 0);
remoteViews.setOnClickPendingIntent(R.id.button, actionPendingIntent);
的的onReceive得到的意图,并做一些东西用的MediaPlayer类重现声音。
我从一些用户那里得知小部件在一段时间后停止工作,并且我发现一些研究是因为任务杀手。看起来,当你杀死TaskKiller中的应用程序时,PendingIntent将从内存中删除,所以当你点击这个小部件时,它不知道该怎么做。
有没有解决方案?我的代码是错误的或者是PendingIntent的默认行为?有什么我可以用来避免TaskKiller阻止我的小工具工作?
问候。
我没有任何任务杀手的问题,但你的代码是我需要什么弄清楚如何PendingIntents工作然后让它们为我的小部件的多个实例及其关联的通知工作。谢谢! – gordonwd 2012-05-04 16:12:12