Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to get return result from activity when calling from Fragment?

I have a Fragment that calls another Activity using:

ProductEditionMaintenanceActivity.class);
Bundle extras = new Bundle();
extras.putString("productCode", productCode);
extras.putInt("productEditionID", 0);
intent.putExtras(extras);
getActivity().startActivityForResult(intent, 1);

and return from the activity:

Intent resultIntent = new Intent();
setResult(Activity.RESULT_OK, resultIntent);
finish();

I tried to use the following in the Fragment

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    //Do something
}

However, I am guessing the intent created passed the reference of the parent Activity of the Fragment therefore onActivityResult on the Fragment does not get called. If that is the case, what do I need to do so the fragment get the result from the callee Activity?

like image 958
user2804013 Avatar asked Sep 22 '13 10:09

user2804013


1 Answers

The fragments onActivityResult will get called AFTER the host activities onActivityResult as long as super.onActivityResult is called from the host activity. See https://stackoverflow.com/a/6147919/552902 for more detail

like image 197
JRomero Avatar answered Nov 16 '22 00:11

JRomero