Can anyone kindly list what are the values of requestCode
to be passed with startActivityForResult()
and their purpose? Also, can you explain on the setResult
parameters available like RESULT_OK
and what else are there? Kindly help.
When you launch an activity for result with requestCode >= 0
, this code will be returned to the First Activity's onActivityResult()
when second activity is finished.You can start multiple Activity
for result from your Activity
. In each case you get the callback to startActivityForResult()
method passing the requestCode. In onActivityResult()
we can use the requestCode to find out for which activity we have received the callback. So to differentiate between the callbacks from Activities
we use different requestCodes.
For eg:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent i = new Intent(FirstActivity.this, SecondActivity.class);
startActivityForResult(i, 1);
Intent i = new Intent(FirstActivity.this, ThirdActivity.class);
startActivityForResult(i, 2);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if (resultCode == RESULT_OK) {
//Get the result from SecondActivity
}
}
else if (requestCode == 2) {
if (resultCode == RESULT_OK) {
//Get the result from ThirdActivity
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With