0

Mainly all I want to do is that when the user uses my app and presses the home button or just exits the app (doesn't matter which way he exits), the next time he enters the app I want to display the first page of my app (instead of the last screen he was in).

I want to do this:

  • when the user exits the app I will delete it from the memory so the app service will keep on going
  • but the next time the user enters the app it will start from the first page

Thanks.

Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
Nir Kigelman
  • 121
  • 3
  • 6

1 Answers1

0

Basically the problem is that you need to know if your app was sent to the background, or not.

If it was sent to background, then when any Activity is started, it loads your "first page" activity in onCreate() before exiting.


Check out some of the solutions in this question I asked some time ago - a lot of the suggestions are really good:

Some of the answers may suit you better than others.

There are 2 basic ideas:

  1. in onPause(), check if your app is one of the ones that is running (see link below)
  2. in onPause() and in onResume(), get a timestamp. If the times differ by more than a few millis, then you can assume the app was sent to background. This can easily be done by creating a base Activity subclass from which all your other activities inherit.

I went with an answer similar to (1) above, on this question:

Community
  • 1
  • 1
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255