performance - Android: Refresh the previous fragment data when pressed backbutton -


i've got 2 fragments, fragment , fragment b. added fragment b on fragment a, using fragmenttransaction().add, means fragment underlying fragment b. there way change data in fragment after did on fragment b , pressed back button fragment b? wish have generic way notify fragment a. because may fragment being overlaid. tried using fragmenttransaction.replace() - works fine refreshing previous page.

just overwrite onbackpressed() in activity , fragment , required calls there.

more callbacks / communication other fragments can found here:

communicating other fragments

public class fragmenta extends fragment {     public void updatemyself(string updatevalue){         log.v("update", "weeee fragment b updated me with" + updatevalue);     } }  public class fragmentb extends fragment {      public interface fragmentbcallbackinterface {         public void update(string updatevalue);     }      private fragmentbcallbackinterface mcallback;      @override     public void onattach(activity activity) {         super.onattach(activity);          try {             mcallback = (fragmentbcallbackinterface) activity;         } catch (classcastexception e) {             throw new classcastexception(activity.tostring()                     + " must implement fragmentbcallbackinterface");         }         //as example update here - wouln't call method until user performs onclick or          letsupatetheotherfragment();     }      private void letsupatetheotherfragment(){         mcallback.update("this update!);     } }   public class myactivity extends activity implements fragmentinterfaceb {      @override     public void update(string updatevalue){           fragmenta fragmenta = (fragmenta) getsupportfragmentmanager().findfragmentbyid(r.id.article_fragment);          if (fragmenta != null) {             fragmenta.updatemyself(updatevalue);         } else {             //replace fragment... bla bla check example code         }     } } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -