This chapter describes using the MAF Application Editor and MAF Features Editor to define the display behavior of the mobile application's springboard and navigation bar and how to designate content by embedding application features.
This chapter includes the following sections:
Section 11.1, "About Using Lifecycle Event Listeners in MAF Applications"
Section 11.2, "About Application Feature Lifecycle Listener Classes"
Within the MAF runtime, classes implement various LifeCycleListener
methods to communicate with event notifications sent from the native operating system frameworks to the JVM. These event notifications describe various states (starting, stopping, or hibernating) for both the mobile application and its embedded application features. MAF invokes the class functions to the JVM using a generic invoke message.
The MAF Application Editor and MAF Feature Editor enable you to declaratively add a lifecycle listener class that MAF calls when events occur.
After you create a mobile application, OEPE creates a lifecycle listener class for the application called LifeCycleListenerImpl.java
. You can implement specific methods using this file, as illustrated in Chapter 25, "Enabling and Using Notifications." The Lifecycle Events sample application provides an example of declaring the event listener class in both the MAF Application Editor and the MAF Features Editor.
To work with this sample application, select File > New MAF Examples, then select LifecycleEvents and click Finish.
Lifecycle listener classes for mobile applications must implement the start
, stop
, activate
, and deactivate
methods of the LifeCycleListener
interface, as illustrated in Example 11-1 to execute the application lifecycle events.
Example 11-1 The LifeCycleListener Interface for a Mobile Applications
package oracle.adfmf.application; public interface LifeCycleListener { void start(); void stop(); void activate(); void deactivate(); }
Note:
The application lifecycle listener is executed with an anonymous user (that is, there is no user associated with any of its methods and no secure web service is called).The AppListener
class, shown in Example 11-2, uses the LifeCycleListener
method calls for starting or stopping events as well as those used when the application is about to hibernate (deactivate
) or return from hibernating (activate
). For more information, see Section 11.1.2, "Timing for Mobile Application Events." See also the LifeCycleListener interface in Java API Reference for Oracle Mobile Application Framework.
Example 11-2 Implementation of the LifeCycleListener Interface
package some.package; import oracle.adfmf.application.LifeCycleListener; public class AppListener implements LifeCycleListener { public AppListener() { super(); } public void start() { // Perform application startup tasks... } public void stop() { // Perform tasks to stop the application... } public void activate() { // Perform appplication activation tasks... } public void deactivate() { // Perform application deactivation tasks... } }
The application controller project of the LifeCycleEvents sample application, described in Appendix G, "MAF Sample Applications," contains a class (LifeCycleListenerImpl.java
) that implements the LifeCycleListener
interface.
Note:
Managed beans and data bindings must be initialized before the startup lifecycle code executes.MAF calls application lifecycle methods at specific times during the mobile application's startup, shutdown, and hibernation. Table 11-1 describes when these methods are called and also notes their Objective-C counterparts.
Table 11-1 MAF Lifecycle Methods
Method | Timing | When Called | Usage | Relation to iOS Application Delegate Methods |
---|---|---|---|---|
|
Called after the mobile application has completely loaded the application features and immediately before presenting the user with the initial application feature or the springboard. This is a blocking call. |
When the application process starts. |
Uses include:
|
This event does not correspond to a specific application delegate method. It is called after the |
|
Called as the mobile application begins its shutdown. |
When the application process terminates. |
Uses include:
|
This is called in the |
|
Called as the mobile application activates from being situated in the background (hibernating). This is a blocking call. |
After the |
Uses include:
|
This is called in the |
|
Called as the mobile application deactivates and moves into the background (hibernating). This is a blocking call. |
Before the |
Uses include:
|
This is called in the |
Because checkpointing saves the application state, you can enable users to continue using the last page of a mobile application that was active before it began to hibernate by adding checkpoint entries to the activate
and deactivate
methods. The lifecycle listener reads the checkpoint entries added to the activate
class and allows the processes to resume after the application has returned from hibernating; users can continue with application uninterrupted by not having to log in a second time. If the application is terminated during hibernation, you can enable the application to resume by specifying that checkpoint information be written to a database or to a device's cache directory as part of the deactivate
method. The application resumes at the same page by reading this checkpoint information during activation.
A mobile application feature lifecycle listener class, such as FeatureListenerPhoneList
, illustrated in Example 11-3, must implement the activate
and deactivate
methods of the LifeCycleListener
interface, as shown in Example 11-3.
Example 11-3 Application Feature LifeCycleListener Interface
package oracle.adfmf.feature; public interface LifeCycleListner { void activate(); void deactivate(); }
Example 11-4 illustrates a class called FeatureListenerPhoneList
that uses the activate
and deactivate
methods by implementing the LifeCycleListener
to show and hide the application feature as described in Table 11-2. These methods hide the application feature when it hibernates, or display it when it returns from hibernating.
Note:
As noted in Java API Reference for Oracle Mobile Application Framework, both theactivate
and deactivate
methods are blocking calls. Because these methods freeze the user interface until they have executed completely, any long-running process included within them will delay the activation of an another application feature. If an application does not require a long-running process to complete before it is deactivated, include it in a background thread rather than within these methods.Example 11-4 Implementing the Application Feature Lifecycle
package some.package; import oracle.adfmf.feature.LifeCycleListener; public class FeatureListenerPhoneList implements LifeCycleListener { public FeatureListenerPhoneList() { super(); } public void activate() { // Perform application activation tasks... } public void deactivate() { // Perform application deactivation tasks... } }
Tip:
The LifeCycle Events sample application provides an example of using theLifeCycleListener
interface at the application feature level through the Feature1Handler.java
and Feature2Handler.java
files. These files are located within the view controller project's Application Sources folder.By implementing an application feature lifecycle listener class, you enable an application feature to automatically obtain any data changes to the applicationScope
variable or to application feature-specific variables that changed when the application feature was deactivated. Table 11-2 describes when the activate and deactivate events are fired for an application feature. For more information, see Java API Reference for Oracle Mobile Application Framework.
Table 11-2 The activate and deactivate Methods for Application Features
Method | Timing | When Called | Usage |
---|---|---|---|
|
Called before the current application feature is activated. |
Called when a user selects the application feature for the first time after launching a mobile application, or when the application has been re-selected (that is, brought back to the foreground). |
Uses include:
|
|
Called before the next application feature is activated, or before the application feature exits. |
Called when the user selects another application feature. |
You can, for example, use the |
By implementing the oracle.adfmf.framework.api.AdfmfSlidingWindowUtilities
interface in the application lifecycle listener (ALCL), you can use an application feature as a sliding window, which displays concurrently with the other application features that display within the navigation bar or springboard. You can use a sliding window to display content that always present within the application, such as a global tool bar, or for temporary (pop-up) content, such as a help window. For information on displaying application features within the springboard or navigation bar, see Section 5.1, "Configuring the Springboard and Navigation Bar Behavior." For information on using the methods of the AdfmfSlidingWindowUtilities
API, refer to Java API Reference for Oracle Mobile Application Framework.