Scenario:
Expected result: Third (last) activity sets a result which is caught on the second activity's onActivityResult
Current result: Third (last) activity sets a result which is caught on the first activity's onActivityResult
How can I set a result on the third activity which will be caught on the second activity's Third (last) activity sets a result which is caught on the second activity's onActivityResult?
Some code snippets:
First activity
public class TestProjActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
Log.i("TAAAG", "1st activity - startActivityForResult");
Intent intent = new Intent(TestProjActivity.this, Activ2.class);
intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
startActivityForResult(intent, 1008);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.i("TAAAG", "1st activity - onActivityResult");
if (resultCode == RESULT_OK) {
Log.i("TAAAG", String.valueOf(requestCode));
switch (requestCode) {
case 1008:
String info = data.getExtras().getString("KEY1");
Log.i("TAAAG", "1st activity - onActivityResult - printing result");
Log.i("TAAAG", info);
break;
}
}
}
}
Second activity
public class Activ2 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("TAAAG", "2nd activity - startActivityForResult");
Intent intent = new Intent(Activ2.this, Activ3.class);
startActivityForResult(intent, 1009);
Intent intent2 = new Intent();
intent2.putExtra("KEY1", "VALUE1");
setResult(RESULT_OK, intent2);
finish();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.i("TAAAG", "2nd activity - onActivityResult");
if (resultCode == RESULT_OK) {
Log.i("TAAAG", String.valueOf(requestCode));
switch (requestCode) {
case 1009:
String info = data.getExtras().getString("KEY2");
Log.i("TAAAG", "2nd activity - onActivityResult - printing result");
Log.i("TAAAG", info);
break;
}
}
}
}
Third activity
public class Activ3 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i("TAAAG", "3rd activity - Inserting Value and finishing");
Intent intent = new Intent();
intent.putExtra("KEY2", "VALUE2");
setResult(RESULT_OK, intent);
finish();
}
}
use Activity flags to forward result to super activity:
intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
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