为什么即使在某些Android设备上使用setCancelable(false)后,AlertDialog.Builder也不会停留很长时间? (例如:MI Pad)。它适用于三星和Moto G3。只有在有GCM时才会发生这种情况。 我使用的代码如下:
public void buildAlertMessageNotification(String message){
final AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getApplicationContext(), R.style.mainActivityTheme));
builder.setMessage(message)
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
try {
new Thread() {
@Override
public void run() {
Looper.prepare();
final AlertDialog alertDialog = builder.create();
alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
alertDialog.show();
Looper.loop();
}
}.start();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}