The alternative to the onActivityResult()
method in Android is the onActivityResult()
method of the Fragment
class. This method is used to receive the result of an activity launched from a fragment, just like the onActivityResult()
method of the Activity
class. Here’s an example of how you can use it:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Check if the request code matches the one we used
if (requestCode == MY_REQUEST_CODE) {
// Check if the result is successful
if (resultCode == RESULT_OK) {
// Process the result data here
}
}
}
Note that you need to override the onActivityResult()
method in your fragment class and include the @Override
annotation. Also, make sure to call the super.onActivityResult()
method before any other code.