私は、発信の終了を検出するブロードキャスト受信機を持っています。その後、私は自分の活動にいくつかのダイアログを表示したい。私は自分の活動にこの方法を試してみました:ブロードキャスト受信者からUIを正しく変更するメソッドをどのように呼び出すのですか?
public static void buildShouldIFollowMessage(String callLength) {
final AlertDialog.Builder builder = new AlertDialog.Builder(c);
builder.setMessage(Constants.CONN_TIMEOUT_MESSAGE+" "+callLength)
.setCancelable(false)
.setPositiveButton("Da", new DialogInterface.OnClickListener() {
public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
//DownloadTask d=new DownloadTask();
//d.execute(Constants.WS_ADDRESS); xmlPredlog.xml
}
})
.setNegativeButton("Ne", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
dialog.cancel();
//showCustomToast("something");
//emptyList.setText("something");
}
});
final AlertDialog alert = builder.create();
alert.show();
}
すべてがコンパイルおよび実行されますが、alert.show()が呼び出されたとき、私は「AndroidRuntime(827)を取得:android.view.WindowManager $ BadTokenException:によって引き起こさ:ウィンドウを追加できません - アプリケーションではトークンnullはありません "。
ブロードキャストレシーバからアクティビティコードを呼び出す必要がある場合の解決策は何ですか。