我想从一个处理程序创建一个警报对话框,当线程终止时会发出信号这是我的代码,它导致:
android.view.WindowManager$BadTokenException: 无法添加窗口 -- 令牌 null 不适用于应用程序
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (dialog != null)
{
dialog.dismiss();
dialog = null;
}
switch (serverResponseCode)
{
case 200:
{
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(getApplicationContext()).create();
alertDialog.setTitle("Super :)");
alertDialog.setMessage("Poza a fost trimisa cu success.");
alertDialog.setButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
} });
alertDialog.show();
serverResponseCode = -1;
break;
}
default:
{
AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(getApplicationContext()).create();
alertDialog.setTitle("Eroare :(");
alertDialog.setMessage("Eroare la trimiterea pozei.");
alertDialog.setButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
} });
alertDialog.show();
break;
}
}
}
};