I have created a simple app for android, that uses buttons to navigate different activities the app starts at page 1, you click on page 2 or 3 button etc and that starts the required activity, simple.
What im having problems with (more of annoyance than problem) when you click HOME or come out of the app, because android doesn’t kill the app straight away it is keeping the page you are on remembered and is opening the app at activity 2 or 3 for example. I want the app when closed to go back to the beginning of the app again and open at 1, i can go back to 1 by clicking back but this is really not what i wanted.
I hope someone can read this and understand, simplest solution possible please
What you need to do is use the Activity lifecycle to your advantage. When a screen is hidden for any reason, its
onPausemethod gets called. When it’s displayed again,onResumegets called. However,onResumeis called even the first time a new Activity is displayed. Another problem is thatonPauseis called when transitioning between Activities.So you ultimately want to “restart” the app when the last Activity’s
onPauseandonResumeare called in succession. Try this class, and have all of your Activity’s extend this instead of Activity.I haven’t tested this code, so it may need a few tweaks, but the logic should be sound.