我的主要活动使用AlarmManager每隔5分钟报警重复一次,以调用对话活动。它通常正常工作。
有时会调用intent,但对话框不会显示给用户;它挂起了触摸屏和菜单按钮。如果我按后退按钮释放,它会挂起。我能够在最近的应用程序中看到对话框。如何在不按后退按钮和挂起触摸屏/菜单按钮的情况下显示对话框?
MainActivity.java:
scheduler = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(getApplicationContext(),AlertDialogShow.class );
scheduledIntent = PendingIntent.getService(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlertDialogShow.java:
AlertDialog.Builder builder = new AlertDialog.Builder(AlertDialogShow.this);//.create();
builder.setCancelable(false);
// Setting Dialog Title
builder.setTitle("Light Brightness");
TextView myMsg = new TextView(this);
myMsg.setGravity(Gravity.CENTER_HORIZONTAL);
myMsg.setTextSize(25);
if(Math.round(lux)>=p)
if(lux<=10243)
myMsg.setText(Math.round(lux)+" "+"lux."+'\n'+'\n'+"Brightness is High.");
else
myMsg.setText(10243+" "+"lux."+'\n'+'\n'+"Brightness is High.");
else
// Setting Dialog Message
myMsg.setText(Math.round(lux)+" "+"lux.");
builder.setView(myMsg);
/* .setButton method is deprecated.so update .setNegativeButton using AlertDialog.Builder*/
// Setting OK Button
builder.setNegativeButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
alertDialog.cancel();
AlertDialogShow.getInstance().finish();
}
});
alertDialog= builder.create();
alertDialog.show();
答案 0 :(得分:0)
而不是
alertDialog.cancel();
AlertDialogShow.getInstance().finish();
使用alertDialog.dismiss()
从当前活动中删除alertDialog。