Issue
My app looks like this:
start activity -> menu -> content -> questionnarie -> questionnarie results
From 'questionnarie results' I want to go to 'menu' Activity after clicking at the back button. I used the method:
@Override
public void onBackPressed() {
startActivity(new Intent(this, Menu.class));
finish();
}
It works but when I click back button again I am in the same Activity and to go to the start Activity back button has to be pressed twice. How can I make this method work properly?
Solution
When you do this:
startActivity(new Intent(this, Menu.class));
This starts a new instance of Menu
. You want to return to the existing instance of Menu
. To do that, you need this:
Intent intent = new Intent(this, Menu.class));
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
This tells Android that you want to go back to the existing instance of Menu
.
Answered By - David Wasser
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.