I have started Activity for result, but how to return string like parameter from that activity ?
What are return types of startActivityForResult in android Options 1 RESULT OK 2 RESULT CANCEL 3 RESULT CRASH 4 A.
In the startActivityForResult() method call you can specify a result code to determine which activity you started. This result code is returned to you. The started activity can also set a result code which the caller can use to determine if the activity was canceled or not.
onActivityResult , startActivityForResult , requestPermissions , and onRequestPermissionsResult are deprecated on androidx.
just use following code block:
Intent intent=new Intent();
intent.putExtra("RESULT_STRING", string);
setResult(RESULT_OK, intent);
finish();
get value from this intent in onActivtyResult method in calling activity:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CREATE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
//Use Data to get string
String string = data.getStringExtra("RESULT_STRING");
}
}
}
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