android - Best practice for handling up navigation in fragments? -


i have simple activity have frame in layout. activity has 3 fragments:

  1. search fields
  2. result list
  3. details

i create first fragment oncreate, , use listener pattern create other 2 fragments when need them. keep track of current fragment. works should.

currently, handle navigation have following code in activity:

@override public boolean onnavigateup() {     if (currentfragment == detailsfragment) {         currentfragment = listfragment;         getfragmentmanager().popbackstack();          return true;     }     else if (currentfragment == listfragment) {         currentfragment = searchfragment;         getfragmentmanager().popbackstack();          return true;     }     else {         return super.onnavigateup();     } } 

is above code correct way handle navigation or there better, cleaner way it?

when add fragment activity, can add addtobackstack(null) , cause button pop fragment previous fragment, there no need override method in case.

also if put fragment replace method works well, if put fragment add method, may cause blank screen if no fragment appeared there before

using replace cause activity quit when last fragment popped


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -