android - code for time limit and intent other class -


can me example code of time limit. can here show complete code how implmeent or have time limit in 1 class intent in next class if user didnt click button. scenario- within 5 sec user must click button intent in class if reached 5 sec time limit intent mainmenu.class - game must fast clicking buttons :) hope can me

a.setonclicklistener(new view.onclicklistener() {          @override               public void onclick(view v) {                 toast.maketext(getapplicationcontext(),"correct!",                         toast.length_short).show();                 intent intent = new intent(getapplicationcontext(),easytwo.class);                 startactivity(intent); 

an intent object reference can modified other java object

  1. create instance variable of intent object

    intent intent ;

  2. assign class value want assign

    intent = new intent(getapplicationcontext(),easytwo.class);

  3. use count down timer check if 5 seconds have passed or not , if passed assign instance of intent new value

example:

public class mainactivity extends activity { intent intent ; countdowntimer cdt; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     button btn = (button) findviewbyid(r.id.button1);     // 5000 5 seconds     // 1000 1 second interval not important in yout case     cdt = new countdowntimer(5000,1000) {          @override         public void ontick(long millisuntilfinished) {}          @override         public void onfinish() {             intent = new intent(getapplicationcontext(),mainmenu.class);         }     };      intent = new intent(getapplicationcontext(),easytwo.class);     btn.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {             startactivity(intent);             //stop timer button clicked             cdt.cancel();         }     });      //start timer     cdt.start(); } } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -