Here is my first activity
code from where I call the second Activity
:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
When you call Activity.startActivityForResult(), you set the requestCode
. Later, this request code is needed by onActivityResult()
in order to determine what Activity is sending data to it. We don't need to supply requestCode
again on setResult()
because the requestCode
is carried along.
The data
is intent data returned from launched intent. We usually use this data when we set extras
on the called intent.
Consider this example:
CALL SECOND ACTIVITY
Intent i = new Intent(MainActivity.this, CheckActivity.class);
startActivityForResult(i, REQUEST_CODE_CHECK);
ON SECOND ACTIVITY, SET INTENT RESULT
getIntent().putExtra("TADA", "bla bla bla");
setResult(RESULT_OK, getIntent());
finish();
BACK TO FIRST ACTIVITY, ONACTIVITYRESULT()
if(requestCode == REQUEST_CODE_CHECK && resultCode == RESULT_OK){
text1.setText(data.getExtras().getString("TADA") );
}
There you go. You should now understand what is Intent data
and how to set and fetch the value.