Search code examples
androidscreen-off

My app closes when screen turns off


I got a problem with my app when the screen turns off (because of system screen timeout) my application finishes. I search but didn't find something helpful. Is it a common problem or does it have a fix?


Solution

  • you shud not call finish() in onPause. it could be called for variety of reasons(check doc.). why you want to kill your activity when user switches app? its not recommended. here are some posts, but there is no api available to detect app going in background.

    How to detect when an Android app goes to the background and come back to the foreground

    http://nathanael.hevenet.com/android-dev-detecting-when-your-app-is-in-the-background-across-activities/