I am developing an application for Android & iPhone using Phonegap+JQuery Mobile. The requirement is to pause the application if a user presses back button on android device. I’ve tried navigator.app.exitApp();
but it does not fulfill the requirement and closes the application instead of pausing it. Can we somehow invoke the onPause() event programmatically?
Asked
Active
Viewed 169 times
0

Cœur
- 37,241
- 25
- 195
- 267

user2436428
- 1,653
- 3
- 17
- 23
-
but do you want to exit the app or just pause the state? – jcesarmobile Nov 05 '14 at 09:53
-
just want to pause the state and send it to background – user2436428 Nov 05 '14 at 11:05
-
1I don't think that's possible with the back button, only with the "home" button. I think the best option is just to block the back button so the user can't quit with it, so he has to use the home button – jcesarmobile Nov 05 '14 at 11:14
-
Yes, this might be an alternate that just prevent the back button functionality But do you have any idea that why we cant invoke onPause() event programitically? Is it just with this event or we can't invoke other events also with our js code? – user2436428 Nov 05 '14 at 11:28
-
invoking onPause() will do nothing, it will just run the code you have on the onPause handler, but it won't quit the app, so there is no point on invoking it. You can invoke it with cordova.fireDocumentEvent('pause', null, true); – jcesarmobile Nov 05 '14 at 11:46
-
1If you really want the back button to act like the home button, you could add an event listener to the back button that first prevents the default behaviour, then emulates the home button by launching a home Intent: [see here](http://stackoverflow.com/questions/3724509/going-to-home-screen-programmatically). You'd need to wrap that Java code in a Phonegap plugin which you could then call from Javascript within your app via the Phonegap API. – DaveAlden Nov 07 '14 at 15:51