I have a broadcast receiver that detects the end of a outgoing call. After that, i want to show some dialog in my activity. I tried with this method in my activity:
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();
}
Everything compiles and runs, but when alert.show() is called, i get "AndroidRuntime(827): Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application".
What is the solution here and for other cases, when you have to call some activity code from broadcast receivers?