Calling onDestroy() when the the app is swapped of the recent screen

657 views Asked by At

I was trying to implement splash screen in android by adding time for which the splash screen is to be shown.

Whenever I close the app by pressing the back button it destroys the activity. If one open the app again from the recent screen it shows the splash screen, but it leads to bad user experience(as they are annoyed by seeing the splash screen again and again, it should only be shown when the user swip of the app from recent screen).

So I thought of adding onPause() and onStop() method inside onBackPressed() method but then the app is never destroyed(i.e. onDestroy isnever called).

How to solve this issue?

1

There are 1 answers

2
Ümañg ßürmån On

Here is the chunk of surprise:

None of the Activity Life-cycle Methods will be called when the app is swiped off

Swiping the app means killing the process of the app and hence it's dead. That's it.

Only onStop() will be called when we press the Recent App button near the Home button.

To implement SplashScreen to appear only for the first time, you can use Shared Preferences and maintain a data as this data will be in your app until the app is uninstalled.

Any other doubts regarding this, please post in comment. We will be happy to help.