Skip to content

Instantly share code, notes, and snippets.

@daichan4649
Created October 4, 2013 01:42
Show Gist options
  • Save daichan4649/6819780 to your computer and use it in GitHub Desktop.
Save daichan4649/6819780 to your computer and use it in GitHub Desktop.
startActivityForResult (FragmentA <-> FragmentB)
// FragmentA (in Activity A)
private void showActivityB(int requestCode) {
Intent intent = new Intent(getActivity(), ActivityB.class);
startActivityForResult(intent, requestCode);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != Activity.RESULT_OK) {
return;
}
String val = data.getStringExtra("key1");
}
// FragmentB (in ActivityB)
private void close() {
Intent intent = new Intent();
intent.putExtra("key1", "val1");
getActivity().setResult(Activity.RESULT_OK, intent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment