I have 4 Activit开发者_StackOverflow中文版ies A,B,C,D now I have in each activity a button of Back and button Cancel
Now I went on the button back to move to the activity that I have before example if I am on B when I press on back I get to A that I have done that by finish but the problem that I have is when I am on example C and I press cancel I should get to A but dose not work I try to make a new activity but don't work.
how can I make my function Cancel to take me back to the activity A?Just use onActivityResult()
in middle activity, and while finishing C just add the line
setResult(5)
in the middle Activity B in onActivityResult
just check in resultcode=5 finish it.
check this link
You can use Intent with flag FLAG_ACTIVITY_CLEAR_TOP
in startActivity
.
So if you have A B C after launching A activity B and C will be closed.
For example on Activity C in cancel button click listener:
Intent cancelIntent = new Intent(this, A.class);
cancelIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(cncelIntent);
精彩评论