我处于一种情况,AlertDialog
应该在特定时间后弹出。
AlertDialog.Builder alertDialog = new AlertDialog.Builder(PDFDisplayActivity.this);
alertDialog.setTitle(" Auto Logout");
alertDialog.setMessage("You will be logged out automatically after 1 minute.");
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
waitTimer = new CountDownTimer(60000, 1000) {
public void onTick(long millisUntilFinished) {
//Toast.makeText(getApplicationContext(), "seconds remaining: " + millisUntilFinished / 1000, Toast.LENGTH_SHORT).show();
}
public void onFinish() {
Intent logout = new Intent(getApplicationContext(), LoginActivity.class);
logout.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(logout);
finish();
}
}.start();
}
});
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//Toast.makeText(getApplicationContext(), "Please logout when you are done reading the agreement.", Toast.LENGTH_SHORT).show();
}
});
alertDialog.show();
在上面的代码中,当Yes
点击时,客户会在一分钟后被自动记录下来。当No
被点击时,不会采取任何行动,但一段时间后,警报应该再次弹出,即,每当客户点击时No
,AlertDialog
应该在指定时间后出现。有什么办法吗?