Display AlertDialog in android after specified time -
i'm in situation where, alertdialog
should pop after specific time.
alertdialog.builder alertdialog = new alertdialog.builder(pdfdisplayactivity.this); alertdialog.settitle(" auto logout"); alertdialog.setmessage("you 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 done reading agreement.", toast.length_short).show(); } }); alertdialog.show();
in code above, when yes
clicked, customer logged of automatically after 1 minute. when no
clicked, no action taken, after time, alert should pop again, i.e, whenever customer clicks no
, alertdialog
should appear after specified time. there way it?
try this,
public handler alerthandler = new handler() { public void handlemessage(message msg) { switch (msg.what) { case 0: //put alertdialog code here break; } }; };
and show alertdialog send message above handler as,
alerthandler.sendemptymessageattime(0,1000/*your time in millis*/);
Comments
Post a Comment