Skip to content

mgatto/cordova-plugin-lifecycle-events-extra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cordova-plugin-lifecycle-events-extra

Cordova Plugin for Extra App Lifecycle Events, including Terminate and Destroy.

Based heavily on:

Similar plugins which may better meet one's requirements include:

Installation

cordova plugin add cordova-plugin-lifecycle-events-extra

Warning! You should not call any interactive Javascript in the event handler! This includes alert() and any other interaction with the user. Ensure that your handler is "headless".

In your JS event handler, you should strong consider wrapping your JS code in setTimeout. Otherwise, AJAX calls, for example, will not work.

Included Additional Lifecycle Events

Usage

Only after the deviceready event has fired, add these event listeners within the deviceready handler's function body:

iOS

Warning! iOS does not broadcast any event upon termination when the app is already in the background!

 document.addEventListener("deviceready", function (event1) {

	 document.addEventListener('willterminate', function (event2) {
		/* iOS cordova quirk */
	    setTimeout(function() {
		    console.log('terminate event has fired.');
	        // more JS here!
	   }, 0);
	});

 }, false);

Android

document.addEventListener('destroy', function () {
    // your JS code here!
});

Browser Platform

Just register a beforeunload event on the body:

window.addEventListener("beforeunload", function (event) {
  event.preventDefault();

  myUnloadFunction("erase all the things!");

  return '';
});

About

Cordova Plugin for Extra App Lifecycle Events, including Terminate and Destroy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published