I have a mainActivity
in which I use my fragment
. and I have two activities Activity1
and Activity2
. first I go to fragment
to Activity2
, when I click back button in Activity2
, I need to back to fragment
page .
it means I need to finish my Activity2
and also finish my Activity1
in one click. how can I get this . here is my back press code on Activity2
.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle arrow click here
if (item.getItemId() == android.R.id.home) {
if(fromString.equalsIgnoreCase("Activity2")){
this.finish();
Activity1.finish();
}else if(fromString.equalsIgnoreCase("Activity1"){
finish(); // close this activity and return to preview activity (if there is any)
}
}
return super.onOptionsItemSelected(item);
}