Skip to content

startFragmentForResult

JingYeoh edited this page Dec 18, 2017 · 1 revision

We offen use startActivityForResult in Activity,and this api is really powerful and useful.But fragment does not support this api,so this library provide this api support.

This method is only worked with the fragment managed by stack.

@Puppet
public class AFragment extend Fragment{
  //start BFragment.
  Rigger.getRigger(this).startFragmentForResult(this, ResultFragment.newInstance(), 1000);
  //...
  public void onFragmentResult(int requestCode, int resultCode, Bundle args) {
    Logger.i(this, "requestCode=" + requestCode);
    Logger.i(this, "resultCode=" + resultCode);
    if (resultCode != Rigger.RESULT_OK) return;
    String string = args.getString(BUNDLE_KEY);
    Logger.i(this, string);
  }  
}
@Puppet
public class BFragment extend Fragment{
  //set result and close.
  Bundle args = new Bundle();
  Rigger.getRigger(this).setResult(Rigger.RESULT_OK, args);
  Rigger.getRigger(this).close();
}