private void startFragmentOrActivityForResult(
     Intent pickIntent, int requestCode, int fragmentId) {
   if (fragmentId == 0) {
     mParent.startActivityForResult(pickIntent, requestCode);
   } else {
     Fragment cFrag = mParent.getFragmentManager().findFragmentById(fragmentId);
     if (cFrag != null) {
       mParent.startActivityFromFragment(cFrag, pickIntent, requestCode);
     }
   }
 }
  @Test
  public void canStartActivityFromFragment() {
    final Activity activity = buildActivity(Activity.class).create().get();

    Intent intent = new Intent(Intent.ACTION_VIEW);
    activity.startActivityFromFragment(new Fragment(), intent, 4);

    ShadowActivity.IntentForResult intentForResult =
        shadowOf(activity).getNextStartedActivityForResult();
    assertThat(intentForResult.intent).isSameAs(intent);
    assertThat(intentForResult.requestCode).isEqualTo(4);
  }