Here i will show you how to use auto close dialog after a particular time using timer class in android .So lets start with coding part :-
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Auto-closing Dialog");
builder.setMessage("After 7 second, this dialog will be closed automatically!");
builder.setCancelable(true);
final AlertDialog dlg = builder.create();
dlg.show();
final Timer t = new Timer();
t.schedule(new TimerTask() {
public void run() {
dlg.dismiss(); // when the task active then close the dialog
t.cancel(); // also just top the timer thread, otherwise, you may receive a crash report
}
}, 7000); // after 7 second (or 7000 miliseconds), the task will be active.
Comments
Post a Comment