Book Image

PhoneGap 4 Mobile Application Development Cookbook

Book Image

PhoneGap 4 Mobile Application Development Cookbook

Overview of this book

Table of Contents (19 chapters)
PhoneGap 4 Mobile Application Development Cookbook
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Resuming your application


Multi-tasking capabilities that are now available on mobile devices specify that the user has the ability to switch from one application to another at any time. We need to handle this possibility and ensure that we can save and restore any process and data when the user returns to our application.

How to do it...

We can use the PhoneGap API to detect when our application is brought back to the foreground of the device:

  1. Firstly, create a new PhoneGap project named resumedemo by running the following command:

    phonegap create resumedemo com.myapp.resumedemo resumedemo
    
  2. Add a 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. We'll also be manipulating the DOM elements, so include a reference to the xui.js file within the head tag. We will also be setting the deviceready listener once the DOM has fully loaded, so let's apply an onload attribute...