2013-12-13 42 views
-2

我的主要活动是使用AlarmManager以每5分钟警报重复一次意图来调用对话活动。它通常工作。警报对话框在Android中不会每5分钟显示一次

有时会调用意图,但对话框不会显示给用户;它挂起触摸屏和菜单按钮。如果我按下后退按钮释放,它会挂起。我能够在最近的应用程序中看到对话框。如何在不按下后退按钮并悬挂触摸屏/菜单按钮的情况下显示对话框?

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(); 
+1

发布您尝试过的代码。 –

+0

你可以分享代码吗? – umerk44

回答

0

而不是

alertDialog.cancel(); 
AlertDialogShow.getInstance().finish(); 

使用alertDialog.dismiss()删除alertDialog形成当前活动。

+0

雅我改变了这个code.but仍然我面临着这个问题。 – user3004089