java - pressing back button application mixes in android -


facing issue pressing button in fragement .pressing application got mixed other fragments.

can 1 me

i have 4 fragements

dealerdetails.java

 rootview.setfocusableintouchmode(true);     rootview.requestfocus();     rootview.setonkeylistener(new view.onkeylistener() {         @override         public boolean onkey(view v, int keycode, keyevent event) {             // log.i(tag, "keycode: " + keycode);             if (keycode == keyevent.keycode_back) {                  // log.i(tag, "onkey listener working!!!");                 // getfragmentmanager().popbackstack(null, fragmentmanager.pop_back_stack_inclusive);                  fragment fragment = new dealerbynamesfragement();                 fragmentmanager fragmentmanager = getfragmentmanager();                 fragmentmanager.begintransaction()                         .replace(r.id.frame_container, fragment).commit();                  return true;             } else {                 return false;             }         }     }); 

by pressing button want show dealerbynamesfragement.java

dealerbynamesfragement.java

    rootview.setfocusableintouchmode(true);             rootview.requestfocus();             rootview.setonkeylistener(new view.onkeylistener() {                 @override                 public boolean onkey(view v, int keycode, keyevent event) {                     // log.i(tag, "keycode: " + keycode);                          if(keycode == keyevent.keycode_back && keycode == keyevent.action_down ) {                              // log.i(tag, "onkey listener working!!!");                             // getfragmentmanager().popbackstack(null, fragmentmanager.pop_back_stack_inclusive);                              fragment fragment = new dealersearchfragment();                             fragmentmanager fragmentmanager = getfragmentmanager();                             fragmentmanager.begintransaction()                                     .replace(r.id.frame_container, fragment).addtobackstack("tag1").commit();                          return true;                     } else {                         return false;                     }                 }             });  pressing redirecting dealersearchfragment.java 

dealersearchfragment.java

 rootview.setfocusableintouchmode(true);             rootview.requestfocus();             rootview.setonkeylistener(new view.onkeylistener() {                 @override                 public boolean onkey(view v, int keycode, keyevent event) {                     // log.i(tag, "keycode: " + keycode);                     if (keycode == keyevent.keycode_back) {                          // log.i(tag, "onkey listener working!!!");                         // getfragmentmanager().popbackstack(null, fragmentmanager.pop_back_stack_inclusive);                          fragment fragment = new homefragment();                         fragmentmanager fragmentmanager = getfragmentmanager();                         fragmentmanager.begintransaction()                                 .replace(r.id.frame_container, fragment).commit();                          return true;                     } else {                         return false;                     }                 }             }); 

do have onbackpressed() in activity?

don't forget set addtobackstack null when calling new fragment activity.

mfragmenttransaction.addtobackstack(null); 

and add onbackpressed() method activity in order finish button process

@override public void onbackpressed() {     if (getfragmentmanager().getbackstackentrycount() == 0) {         this.finish();     } else {         getfragmentmanager().popbackstack();     } } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -