everyone. I have started to write(1-month-old) Android apps and I am pretty new this stuff.
I have a activity X. On that activity X, I have four different buttons calls four different activities. On those three activities, I have button, and I am returning data to activity X after I pressed button. Also, on the activity X, I may not call all three of the activies. I might call just 1,3 or just 2,3. I have looked a lot but I could not find what I seek for.
EDIT: when I put finish();
to activity 1,2,3, I could call one of the activies(assume activity one called) and able to grab data, and returns the Activity X, but when I started to call other one (assumed activity 2 called), I could go to this activity, but I cannot return from it since it does know where to return.
This is what I seek for:
Activity X-> 1st activity -> return data1 to X
Activity X-> 2nd activity -> return data2 to X
Activity X-> 3rd activity -> return data3 to X
Activity X-> send data1 + data2 +data3 to 4th activity
I started my three activities on Activity X
like this under onClick
method (data_global
is global on Activity X class)
case R.id.btn1:
Intent i = new Intent(this, Activity1.class);
startActivityForResult(i, 200);
break;
case R.id.btn2:
i = new Intent(this, Activity2.class);
startActivityForResult(i, 201);
break;
case R.id.btn3:
i = new Intent(this, Activity3.class);
startActivityForResult(i, 202);
break;
case R.id.btn4:
i = new Intent(this, Activity4.class);
i.putExtra("Extra", data_global);
startActivity(i);
break;
I take my data from here on Activity X
under onActivityResult
method:
switch (requestCode) {
case (200): {
if (resultCode == Activity.RESULT_OK) {
if (data.getStringExtra("Extra1").length() != 0) {
data_global += data.getStringExtra("Extra1");
}
}
break;
}
case (201): {
if (resultCode == Activity.RESULT_OK) {
if (data.getStringExtra("Extra2").length() != 0) {
data_global += data.getStringExtra("Extra2");
}
}
break;
}
case (202): {
if (resultCode == Activity.RESULT_OK) {
if (data.getStringExtra("Extra3").length() != 0) {
data_global += data.getStringExtra("Extra3");
}
}
break;
}
And any of activity 1 or 2 or 3 code is like that:(X
is at the end on Extra referring to 1,2,3)
case R.id.btnSave:
Intent resultIntent = new Intent();
resultIntent.putExtra("ExtraX", "name");
setResult(Activity.RESULT_OK, resultIntent);
finish();
break;
How can I solve my problem? Many thanks.
Please login or Register to submit your answer