Android - Lifecycle Module Interface
The LifecycleModule
interface should be used when you want to hook into the underlying
logic of the running activity and/or application. It is useful for modules that run in the
background tracking application lifecycle, track user authentication, or handle intent
callbacks.
Implementation
Create a class and have it inherit the LifecycleModule
. Once inherited, override the
functions provided and add your logic as required.
/**
* Example LifecycleModuleActivity.
*
* A LifecycleModule hooks into the underlining lifecycle of the main activity that controls the application.
* Through this you are able to not only receive callbacks for standard activity event changes, but can also
* listen to and react to specific events that fall inline with a user's experience.
*/
class LifecycleModuleActivity(private val sdkUtils: SdkUtils): LifecycleModule {
/**
* Called when the system first creates the activity and enters the Created state. This is where
* your basic application startup logic should exist, triggered only once and remains for the
* entire life of the application.
*
* It is not advised to conduct any API calls or logic that could hang at this point.
*/
override fun onCreate() {}
/**
* Called when the activity enters the Started state. This callback comes after [onCreate].
* [onStart] is where the activity becomes visible to the user, as the application prepares for
* the activity to enter the foreground and become interactive.
*/
override fun onStart() {}
/**
* Called after [onStart], this is the state in which the application interacts with the user.
* It will stay in this state until something takes focus away (minimizing the application,
* opening another application, etc).
*
* This is where it is advised that you make your API calls, or start any larger processes.
*/
override fun onResume() {}
/**
* Called as the first indication that the user is leaving the application, meaning that this
* activity is no longer in the foreground. This is where you will want to pause any operation
* that should not be running in the Paused state.
*
* Keep in mind, that this state can be triggered by several different means, including a dialog
* modal being displayed overtop, application is now running in a multi-window mode, or any
* other event that would interrupt the lifecycle.
*/
override fun onPause() {}
/**
* Called when the application is no longer visible to the user and has entered a Stopped state.
* This will be called when the application has been terminated to allow cleanup before being
* fully removed.
*
* This is where you should remove and release any resources being used. It can also be a good
* time to perform any CPU intense shutdown operations, if required.
*/
override fun onStop() {}
/**
* Perform any final cleanup here before the activity is destroyed. This can happen either
* because the activity is finishing (someone called finish() on it), or because the system
* is temporarily destroying this instance of the activity to save space. You can distinguish
* between these two scenarios with the isFinishing() method.
*
*/
override fun onDestroy() {}
/**
* Called when a user has failed to authenticate or login. If an error is available, it will
* be passed through.
*
* @param errorMessage The error that has been captured
*/
override fun onUserAuthFailed(errorMessage: String) {}
/**
* Called when a successful login has occurred.
*/
override fun onUserAuthSuccess() {}
/**
* Called after the session has been cleared and the user has been fully logged out.
*/
override fun onLogout() {}
/**
* Called when the first UUX screen (login) is displayed to the user. Useful if you needed to
* start a process once the UUX has been displayed.
*/
override fun onUUXLoaded() {}
/**
* Called when the landing page is reached.
*/
override fun onLandingPageReached() {}
/**
* Called when a new Intent is received and needs to be determined if the intent should be
* handled or discarded. If handled here, then return true so that the main application does
* not attempt to handle it itself. If not handled here, then return false, so that the main
* application will handle the intent itself.
*/
override fun shouldHandleNewIntent(intent: Intent): Boolean {
return false
}
}
Update Your settings.json
Ensure your settings.json
file in the root of the DevApp is updated to reflect your
module changes. Learn more in Configuring settings.json.