Skip to content Skip to sidebar Skip to footer

Onactivityresult() Not Called After Startactivityforresult() With Intent.action_get_content

I got my main Activity which holds different Fragment's, one fragment gives the user a possibility to open a DialogFragment. That dialog opens a list of sound files and the dialog

Solution 1:

Managed to figure out what the problem was... In my manifest I have declared my Activity as android:noHistory="false" and this was the problem. After setting it to android:noHistory="true" for my activity and firing my Intentthe following way it worked like a charm.

Intentintent=newIntent(Intent.ACTION_GET_CONTENT);
intent.setType("audio/mpeg");           
getActivity().startActivityForResult(intent, ADD_SOUND_REQUEST_CODE);

And just like that, the onActivityResult() in my activity was triggered just as it should and after that I followed @Rohit5k2's advice on how to get my Fragment's OnActivityResult() triggered and all has worked really great!

@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
    MyFragmentfragmentObject= getSupportFragmentManager().findFragmentById(R.id.container);
    fragmentObject.onActivityResult(requestCode, resultCode, data);
}

Thanks guys for your help!

Solution 2:

Do this in your activity which holds the fragments

@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data)
{
    MyFragmentfragmentObject= getSupportFragmentManager().findFragmentById(R.id.container);
    fragmentObject.onActivityResult(requestCode, resultCode, data);
}

then onActivityResult() in your fragment will be called.

Solution 3:

In fragments you'd generally use this.startActivityForResult(...) and override the fragment's method onActivityResult(...). Since your case is a DialogFragment this would be useless as the dialog would be destroyed after pressing one of its buttons.

That means you correctly called getActivity().startActivityForResult(...) but since the caller is the activity, the activity is the one that has to implement the onActivityResult(...) method. No fragments receive the callback when taking this approach.

Post a Comment for "Onactivityresult() Not Called After Startactivityforresult() With Intent.action_get_content"