Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
19
rated 0 times [  20] [ 1]  / answers: 1 / hits: 19485  / 10 Years ago, sat, august 30, 2014, 12:00:00

I am using phone gap to develop an android app. Is it possible to check if the app is running in background or foreground using javascript?



As we can close the app by calling navigator.app.exitApp(). We can perform other functions as well.



Is there any function which can tell us whether the app is running in background or foreground?



Actually, I want to make the app working in following way.



If app is in foreground, it should show an alert message rather than a push notification.
If app is in background it should show a push notification.



Many thanks Indeed.


More From » android

 Answers
51

Pause :



This is an event that fires when a Cordova application is put into the background.



document.addEventListener(pause, yourCallbackFunction, false);


Details



Cordova consists of two code bases: native and JavaScript. While the native code puts the application into the background the pause event is fired.



Typically, you will want to attach an event listener with document.addEventListener once you receive the Cordova 'deviceready' event.
Supported Platforms




  • Android

  • BlackBerry WebWorks (OS 5.0 and higher)

  • iOS

  • Windows Phone 7



Quick Example



document.addEventListener(pause, onPause, false);

function onPause() {
// Handle the pause event
}


Resume :



This is an event that fires when a Cordova application is retrieved from the background.



document.addEventListener(resume, yourCallbackFunction, false);


Details



Cordova consists of two code bases: native and JavaScript. While the native code pulls the application from the background the resume event is fired.



Typically, you will want to attach an event listener with document.addEventListener once you receive the Cordova 'deviceready' event.
Supported Platforms




  • Android

  • BlackBerry WebWorks (OS 5.0 and higher)

  • iOS

  • Windows Phone 7



Quick Example



document.addEventListener(resume, onResume, false);

function onResume() {
// Handle the resume event
}


More Information here :



http://docs.phonegap.com/en/2.2.0/cordova_events_events.md.html#resume



http://docs.phonegap.com/en/2.2.0/cordova_events_events.md.html#pause


[#69610] Wednesday, August 27, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
diontajm

Total Points: 391
Total Questions: 104
Total Answers: 104

Location: Netherlands
Member since Mon, Jun 7, 2021
3 Years ago
;