Keep application from crashing when phone sleep/locked

1.6k Views Asked by At

Hi guys as the title says I am trying to keep my application alive so to speak when the phone locks.

In detail my app would be open and running fine if I leave my phone alone for a while and unlock it my application is frozen and can't do anything. Now this only happens on some devices for some weird reason but I am wondering is there a way to manage these kind of things?

Thanks

2

There are 2 best solutions below

1
On

Implement the onPause and onStop on your activity.....

To see if they are being called....

0
On

I have been trying to overcome this kind of issue in a few apps as well. My research points me here: Android - Activity Lifecycle as it states this:

However, if the system destroys the activity due to system constraints (rather than normal app behavior), then although the actual Activity instance is gone, the system remembers that it existed such that if the user navigates back to it, the system creates a new instance of the activity using a set of saved data that describes the state of the activity when it was destroyed. The saved data that the system uses to restore the previous state is called the instance state and is a collection of key-value pairs stored in a Bundle object.

So, we need to be leveraging the savedInstanceState Bundle for cleanly packing and unpacking each Activity and Fragment.

I'll work on an example for you ASAP.