Black screen when opening app after a few hours of inactivity

Viewed 490

I am working on a minimal open-source Launcher (wikipedia) for Android.

When I run it on a phone, put that on standby and unlock it after 4 - 6 hours, all I get is a black screen.

I hope this has some general solution and is not only caused by my code. That way answers to this question will also be useful to everyone else on here.

Relevant mentions for my code

In the Android Manifest XML I declared the main activity to be a launcher (home screen). The main activity (MainActivity.kt) has an onCreate function, only refreshes a clock and checks for some OnTouch events. The full project code can also be seen on GitHub.

Go to the related issue on Github.

1 Answers

You should try implementing onResume() if you haven't already. It is possible that the app has not stopped and as such onStart() would not be called when you unlock your phone.

Where an app has paused, it would just call onResume() instead. You can try putting your code here to recreate the views as needed. You can also save any relevant user information in onPause() and reload it in onResume(). This will allow you to preserve a consistent user experience and avoid memory leaks caused by, for example, referring to objects that no longer exist.

Let me know if it works, good luck.

The Activity Lifecycle

Related