Official Content

Sometimes the application needs to perform some actions when its execution state changes. For example, when the application starts, when it goes to background or when it comes back to foreground again. This external object allows asking for the application's execution state, and to code an event to manage state changes.

AppLifeCycle Image

Domains

ApplicationState domain

This domain is defined in order to identify the application execution state.
It is based on Numeric(1) with the following enumerated values:

Active  The application is running in foreground.
Inactive The application is running in foreground but does not respond to events, i.e., when a phone call arrives in the device. Available only in iOS.
Background The application is running in background.
NotRunning The application is not running at all. Used only in the AppStateChanged event.

Properties

ApplicationState

It is a read-only property automatically set to the application current execution state.
The property only returns the values Active, Inactive (iOS only) or Background. NotRunning value is never returned by the property.
This property replaces the use of Interop external object ApplicationState property.

Events

AppStateChanged event

Notifies when the application's execution state changes.
This event must be used only in the Smart Devices Main object

Input

oldState: ApplicationState
newState: ApplicationState

Output  None

Example

If you need to execute something when the application is starting
Event AppLifecycle.AppStateChanged(&old, &new)
    Composite
        if &old = ApplicationState.NotRunning
            // your code
        endif
    EndComposite
EndEvent
If you need to execute something when the application is going to background
Event AppLifecycle.AppStateChanged(&old, &new)
    Composite
         if &new = ApplicationState.Background
             // your code
         endif
    EndComposite
EndEvent

Scope

Generators:  AppleAndroid

Availability

This external object is available as of GeneXus 16 upgrade 2.



Last update: February 2024 | © GeneXus. All rights reserved. GeneXus Powered by Globant