您好我正在尝试从菜单项中调用一个函数。但我得到了这个例外。android.view.WindowManager$BadTokenException: 无法添加窗口 -- 令牌 null 不适用于应用程序
这是我的代码..
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.layout.menu1, menu);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId())
{
case R.id.write :
writeToTag();
return true;
case R.id.exit :
exitApplication();
return true;
default :
return super.onMenuItemSelected(featureId, item);
}
}
private void exitApplication() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(getApplicationContext());
alertDialog.setMessage("Do You Want To Exit..?")
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
NFCTagWriterActivity.this.finish();
}
}).setNegativeButton("No",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onStart();
}
}).show();
AlertDialog alert = alertDialog.create();
}