I have a problem with the “back” button that is on my device
in my project there are a few layout and class. Let’s call them A, B, C, D.if I run the project starts from the layout “A” and then “B”, “C”, “D”. on my layout position “D” and press the back button found on the device, I would go back to layout “C”, and if pressed again will return to “B” and again to the “A”.
I really want is if I hit “back” on my device, if I was in the layout “D” then I will remain on the layout of “D”. if I was in the layout “C” then I’ll stick to layout “C”.
what should I add?
In your Activity, you can override onBackPressed and do all the handling you want to do in there. The documentation is available here.
You’ll need to keep state variables to know where you’re at and what needs to be displayed next when the user press back…
You can always call
super.onBackPressed()when you want to just use the default behavior too (finishing the current activity)