I read a million of topics related but none of them is updated and satisfies my question. maybe my problem is different. Do you know when you press the home button during a session inside an app and then you reopen the app after a few seconds? the app shows the exact point you were looking at. If you close an app pressing many times the back button instead(or you permanently close it) it shows the splash screen when you reopen it. I want to emulate this behaviour: everytime a user presses the home button or he/she closes my app it MUST reload the splash screen. now the question: how can I terminate my app when it goes in background OR force the splash screen when it reloads? I tried putting some code into the onResume of every activity, but switching between the activities OBVIOUSLY executes that code too and the normal flow of the app would be broken. Can you help me please? Thank you very much
Asked
Active
Viewed 54 times
0
-
please post your code – Vyacheslav Jun 11 '17 at 14:42
-
too long, which parts do you need? – Fausto Jun 11 '17 at 14:44
-
the major events – Vyacheslav Jun 11 '17 at 15:02
-
look up at the activity lifecycle. Call the onDestroy method on exit – John P Jun 11 '17 at 15:08
2 Answers
0
You cannot override the home button click event.
There are many ways to detect that the app has gone to background, which are discussed in a thread here.

Nabin Bhandari
- 15,949
- 6
- 45
- 59
-
ok, in fact it gives nullpointer on the if when I start the app: it executes the code above 3 times and on the third execution intent is null – Fausto Jun 11 '17 at 15:11
-
sorry my bad. check https://stackoverflow.com/questions/4414171/how-to-detect-when-an-android-app-goes-to-the-background-and-come-back-to-the-fo – Nabin Bhandari Jun 11 '17 at 15:45
-
already read.. nothing good. someone uses onPause-onResume, but it doesn't work with many activities, someone uses the timer, but it doesn't fit my situation. – Fausto Jun 11 '17 at 22:58
0
Recipe: call finish()
of activity in onPause()
event exept when you launcha new activity.

Vyacheslav
- 26,359
- 19
- 112
- 194
-
so I should call finish() inside the onPause() everytime except when I launch a new activity? if yes: how to check inside the onPause if I'm launching a new activity? – Fausto Jun 11 '17 at 15:19
-
for instance, create a new boolean flag: `startsNewActivity = true; startActivityForResult();` inside `onActivityResult(){startsNewActivity = false};` – Vyacheslav Jun 11 '17 at 15:22
-