I have an application in which there is a menu, and depending on which button you click on the menu, a new action opens. I want every screen to have a back button that will take you to the previous screen, so I'm wondering how do I do this?
Here is the code I used that works:
backButton = (ImageButton) findViewById(R.id.back_button);
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
However, its not a good programming practice for me to put this code in all my actions. How do I create some kind of stack that saves all pages viewed and uses them to return to the previous page?
I need to put the return button in my application so that I cannot use the existing one in the ActionBar.
source
share