java - onBackPressed with Fragments Android -


i trying implement onbackpressed on activity 3 fragments. issue implemented "press again exit" after time method when button clicked twice returns previous fragment, not quitting. happens when fragment called (i.e if open game , exit straight away works charm). onbackpressed method on mainactivity looks this;

@override public void onbackpressed() {      if(getsupportfragmentmanager().getbackstackentrycount()!=0) {         getsupportfragmentmanager().popbackstack();     }     this.findviewbyid(r.id.linearlayout1).setvisibility(view.visible);     if(mbackpressed + time_interval > system.currenttimemillis() && getsupportfragmentmanager().getbackstackentrycount()==0){         super.onbackpressed();         system.exit(0);         this.finish();     }     else { toast.maketext(getbasecontext(), "press once more exit", toast.length_short).show(); }      mbackpressed = system.currenttimemillis(); } 

i want check if user in mainactivity layout evade using popbackstack. solution appreciated, provide more information if not enough.

thanks, bektaş

if want quit, ignore stack altogether. use code.

@override public void onbackpressed() {     this.findviewbyid(r.id.linearlayout1).setvisibility(view.visible);     if(mbackpressed + time_interval > system.currenttimemillis()){         this.finish();         return;     }     else {         toast.maketext(getbasecontext(), "press once more exit", toast.length_short).show();      }     mbackpressed = system.currenttimemillis(); } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -