私はアプリケーション(インスタントボタンと呼ばれる)を開発しましたが、そのアプリにはウィジェット機能があります。このウィジェットは、ウィジェットのonClickにPendingIntentを使用します。
私の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を回避してウィジェットの動作を停止するために使用できるものはありますか?
ご挨拶。