/Ti.AppLifecyle

Titanium module for app events in android

Primary LanguageJavaOtherNOASSERTION

#Ti.AppLifecycle

This is a Titanium module for detecting a couple app events.

Thanks to Roamler in Amsterdam for sponsoring and René for patience and support.

A description is available too.

#Events

##paused The user has left the app. I.e. by calling launch screen or starting a new activity from the app.

##resumed The user comes back to the app

##screenoff "The screen is black" (Button Power off, or sleep)

##screenon Screen reopened and app is in foreground again

#TestInterval In order to properly read the paused and resumed events we need a TestInterval as Android does not provide an event for this. A good TestInterval would be 200-500ms. If the testInterval is too long it might not be able to trigger an event as the app is already paused at that stage.

You can specify the test interval (in ms) in tiapp.xml:

<property name="LIFECYCLE_TESTINTERVAL" type="int">500</property>

##Usage

You have only to include in tiapp.xml:

<module platform="android">de.appwerft.applifecycle</module>

In the app it is not needed to require this module. Just including it in tiapp.xml is enough to get it to work

In the app you will receive the events through Ti.App.addEventListener() as shown below.

["screenon screenoff paused resumed"].split(' ').forEach(function(eventName){
    Ti.App.addEventListener(eventName, function() {
        console.log(arguments[0]);
    });
});

// static pull:
require("de.appwerft.applifecycle").isInForeground();  // true/false