O'Reilly logo

PhoneGap 4 Mobile Application Development Cookbook by Zainul Setyo Pamungkas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Pausing your application

Although we want our users to spend their time solely on our application, they will inevitably leave our application to open another one or do something else entirely. We need to be able to detect when a user has left our application but not closed it down entirely.

How to do it...

We can use the PhoneGap API to fire off a particular event when our application is in the background of the device:

  1. Firstly, create a new PhoneGap project named pausedemo by running the following command:
    phonegap create pausedemo com.myapp.pausedemo pausedemo
    
  2. Add the devices platform. You can choose to use Android, iOS, or both:
    cordova platform add ios
    cordova platform add android
    
  3. Open www/index.html and let's clean up unnecessary elements. So ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required