solomon staggs
Posts: 0
Joined: Thu Nov 21, 2013 1:17 am

For an Ionic project, where and how should I listen for phonegap's resume event?

I need to navigate back to a login screen whenever the user switches back to my app, or minimizes it then opens the app again (via the home button on iOS for instance).

I know that Phonegap has a "resume" event that I can use, but for the life of me I can't figure out where I can add the addEventListener code to take advantage of the event.

Where should I add the code? The index page, on each individual page?

Should I use document.addEventListener, $window.addEventListener, $rootScope.$on, or something else?

Anything else I may be missing?

Thanks

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

For an Ionic project, where and how should I listen for phonegap's resume event?

Hello,

Please use
predocument.addEventListener("pause", yourCallbackFunction, false);/pre
on the index page.
http://docs.phonegap.com/en/4.0.0/cor...

solomon staggs
Posts: 0
Joined: Thu Nov 21, 2013 1:17 am

For an Ionic project, where and how should I listen for phonegap's resume event?

Hello, thanks for your reply.

Any place in particular on the index page? Could I add it to the init scope function?

solomon staggs
Posts: 0
Joined: Thu Nov 21, 2013 1:17 am

For an Ionic project, where and how should I listen for phonegap's resume event?

Thanks again for your help.

I got it working by using the following code in the init function of the index page.

The $scope.$apply(); was key.

document.addEventListener(
"deviceready",
function()
{
document.addEventListener(
"pause",
function()
{
Apperyio.navigateTo("loginScreen", {});
$scope.$apply( );
},
false);
},
false);

Return to “Issues”