Reputation: 3466
I am having an activity with custom list view. In my list view there are two types of items, with different layout. On items there is a switch and when I turn off the switch I go to Activity A, and when I turn on the switch I go to Activity B.
Here is my code:
Switch enable = (Switch) rowView.findViewById(R.id.enable);
enable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
Intent intentChange = new Intent(getContext(), ActivityA.class);
intentChange.putExtra(PROPERTY, "test1");
((Activity)getContext()).startActivityForResult(intentChange, 100);
} else {
Intent newIntent=newIntent(getContext(),ActivityB.class);
((Activity)getContext()).startActivityForResult(newIntent, 200);
}
}
});
In each of these activities I call this:
Intent changedIntent=new Intent();
changedLimitIntent.putExtra("changed",changed);
changedLimitIntent.putExtra("changedDesc","desc);
setResult(Activity.RESULT_OK,changedIntent);
finish();
In my activity with custom adapter I have this code:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == ActivityA.REQUEST_CODE) {
....
} else if (requestCode == ActivityB.REQUEST_CODE) {
.....
}
}
}
This work OK for me, however, when I receive the result from Activity A or Activity B on the activity with custom list view, and when I click back button is how I have this activity as many times I wait for result from other activities on back stack. I don't know what the problem is. I don't like to have my activity as many times I wait for result from other activities.
I hope I was clear with my question.
Upvotes: 1
Views: 809
Reputation: 1012
Try this to launch new activity. Hope it will help you.
Activity_A.this.finish();
Intent intentSettings = new Intent(Activity_A.this, Activity_B.class);
intentSettings.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intentSettings);
Upvotes: 1