android - wait a little before finish my activity -
what's best way wait before activity finished?
in fact launch new activity named masternumber mainactivity "startactivityforresult". masternumber send sms , shows toast "sms sent", masternumber activity closed toast showed in mainactivity.
here content of mainactivity:
//lorsqu'on clique sur le bouton "send" button button1 = (button) findviewbyid(r.id.masterbutton1); button1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { try { smsmanager smsmanager = smsmanager.getdefault(); smsmanager.sendtextmessage(automatikrn, null, "#00#", null, null); toast.maketext(getapplicationcontext(), "sms sent!", toast.length_long).show(); } catch (exception e) { toast.maketext(getapplicationcontext(), "sms failed, please try again later!", toast.length_long).show(); e.printstacktrace(); } finish(); } });
and here content of masternumber (activity)
//lorsqu'on clique sur le bouton add master number button button2 = (button) findviewbyid(r.id.mainbutton2); button2.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { //on va appeler l'activité masternumber (#recipientnumberautomatik-1) intent setmasternumber = new intent(mainactivity.this, masternumber.class); setmasternumber.putextra("mn", recipientnumber); //on lui fournit le n° du dest. afin qu'il soit saisit automatiquement startactivityforresult(setmasternumber, 1); } });
try :
//lorsqu'on clique sur le bouton "send" button button1 = (button) findviewbyid(r.id.masterbutton1); button1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { try { smsmanager smsmanager = smsmanager.getdefault(); smsmanager.sendtextmessage(automatikrn, null, "#00#", null, null); toast.maketext(getapplicationcontext(), "sms sent!", toast.length_long).show(); } catch (exception e) { toast.maketext(getapplicationcontext(), "sms failed, please try again later!", toast.length_long).show(); e.printstacktrace(); } new handler().postdelayed(new runnable() { @override public void run() { finish(); } }, toast.length_long); } });
by using postdelayed runnable, actions places inside run() method executed after toast.length_long time has passed.
Comments
Post a Comment