0

I use the following code to pass data between activities:

ActivityOne.class

Intent mIntent = new Intent(getBaseContext(), ActivityTwo.class); mIntent.putExtra("test", test_value); startActivityForResult(mIntent, 0); @Override protected void onActivityResult (int requestCode, int resultCode, Intent data) { Log.i(TAG, "Result: "+resultCode); // OK final String test_value = data.getExtras().getString("test"); // fails here since data is null Log.i(TAG, "Test: "+test_value); } 

ActivityTwo.class

@Override protected void onStart() { super.onStart(); ... setResult(result); // pass the result back to ActivityOne finish(); // yes, I close it immediately after start ;) 

So, how should I properly pass Intent data (test_value in the code above) from ActivityOne to ActivityTwo (this part works well) and then back to ActivityOne (this part doesn't work, data at onActivityResult is null)?

1 Answer 1

1

You need to pass the Intent back.

Try:

 setResult(result, getIntent()); 

This will send the original intent that started Activity2 (i.e. created in Activity1) back to Activity1

Reference Activity.getIntent

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.