CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2019-09-12
by Mehul Kabaria

Original Post

Original - Posted on 2013-06-12
by Vinayak



            
Present in both answers; Present only in the new answer; Present only in the old answer;

> Write below code in your Activity that contains your fragment.
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.dualPane); fragment.onActivityResult(requestCode, resultCode, data); }
It will overridden `onActivityResult` in your child `fragment`.
> Below code you have to add in your child `Fragment`.
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // In fragment class callback }
**Option 1:** If you're calling `startActivityForResult()` from the fragment then you should call `startActivityForResult()`, not `getActivity().startActivityForResult()`, as it will result in fragment onActivityResult().
*If you're not sure where you're calling on `startActivityForResult()` and how you will be calling methods.*
**Option 2:**
Since Activity gets the result of `onActivityResult()`, you will need to override the activity's `onActivityResult()` and call `super.onActivityResult()` to propagate to the respective fragment for unhandled results codes or for all.
*If above two options do not work, then refer to option 3 as it will definitely work.*
**Option 3:**
An explicit call from fragment to the onActivityResult function is as follows.
In the parent Activity class, override the onActivityResult() method and even override the same in the Fragment class and call as the following code.
In the parent class:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.dualPane); fragment.onActivityResult(requestCode, resultCode, data); }

In the child class:
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // In fragment class callback }

        
Present in both answers; Present only in the new answer; Present only in the old answer;