Is there a way to detect when the phone goes to sleep?


I’m building a app and i somehow need to know when the phone goes to sleep or when it wakes up from sleep so i can reload a controller.

If you have any ideas of how i can do that, they would be much appreciated.

Thanks Sindri

I found the answer myself. Even though i don’t load the controller, with this you can call a function when the phone comes back from sleep. Tried it on iOS and worked.

document.addEventListener(“resume”, onResume, false);

    function onResume() {
1 Like

If you are not specific to sleep event you can utilize onPause event. You can put below mentioned code to your app controller.

    document.addEventListener("resume", onResume, false);
document.addEventListener("pause", onPause, false);

function onResume() {

function onPause() {
	// use $state.go to go to any of the states or use $state.reload()