Reputation: 167
i have two sub activities apart from main activity.
The sequence of calls go like this.
Main --> Sub_Activity1 ,then Sub_Activity1 returns to Main Activity. Main ---> Sub_Activity2, then Sub_Activity2 returns to Main Activity.
But it is not happening. As far i can see only the 2nd sub activity is getting called, it is skipping the first one . but when i disable/comment out one of the sub activities the other one is working well. but when i want to call one after another it is calling only the second one. where am i going wrong. here is my code
Main Activity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button) findViewById(R.id.btn1);
txt = (TextView) findViewById(R.id.textview1);
txt.setText("hello world");
in1= new Intent(TestActivity.this,Number.class);
//startActivity(in1);
startActivityForResult(in1, MY_DATA_CHECKCODE);
in2= new Intent(TestActivity.this,Message.class);
//startActivity(in1);
startActivityForResult(in2, MY_DATA_CHECKCODE1);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECKCODE) {
num= data.getStringExtra("number");
if(num!=null)
txt.setText(num);
}
else if (requestCode == MY_DATA_CHECKCODE1) {
num= data.getStringExtra("number");
if(num!=null)
txt.setText(num);
}
}
subactivity1 and subactivity2 codes are same which are used to add some string data to a new intent which can be retrieved in the main intent.
number = et.getText().toString().trim();
in= new Intent();
//in.putExtras(b);
in.putExtra("number", number);
setResult(Activity.RESULT_OK,in);
i have changed the variables to use different request codes as well. they are MY_DATA_CHECKCODE and MY_DATA_CHECKCODE1.is there anything wrong in handling the return values in onActivitResult function.please give me ur suggestions to fix this problem. i have googled and but could not find proper solution for it.
Upvotes: 0
Views: 161
Reputation: 11419
Android doc doesn't say what happens if you call startActivityForResult twice. I think you should put the call to the second activity in the onActivityResult for the first one.
At least this is the way I would do it
Upvotes: 2