Class POBAppStateMonitor
-
- All Implemented Interfaces:
-
android.app.Application.ActivityLifecycleCallbacks,com.pubmatic.sdk.common.session.POBAppStateMonitoring
public final class POBAppStateMonitor implements POBAppStateMonitoring, Application.ActivityLifecycleCallbacks
This class monitors the lifecycle events of the host application's activities to determine whether the app is in the foreground or background. It uses the ActivityLifecycleCallbacks to track activity lifecycle events and determine the app's state.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfacePOBAppStateMonitor.POBAppLifecycleListenerImplement this interface to receive callbacks when the application moves to the foreground or background. Note that these callbacks will be executed on a background thread.
-
Method Summary
Modifier and Type Method Description Unitrelease()Releases the lifecycle monitor and unregisters the callbacks. UnitaddAppLifecycleListener(POBAppStateMonitor.POBAppLifecycleListener listener)Sets the listener to receive lifecycle events. UnitremoveAppLifecycleListener(POBAppStateMonitor.POBAppLifecycleListener listener)Removes a listener from receiving lifecycle events. UnitonActivityCreated(Activity activity, Bundle savedInstanceState)UnitonActivityStarted(Activity activity)Called when an activity is started. UnitonActivityResumed(Activity activity)UnitonActivityPaused(Activity activity)UnitonActivityStopped(Activity activity)This lifecycle callback posts a delayed runnable to check if the app is in the background. UnitonActivitySaveInstanceState(Activity activity, Bundle outState)UnitonActivityDestroyed(Activity activity)final static POBAppStateMonitorgetInstance(Application application)Returns the singleton instance of the POBAppStateMonitor. -
Methods inherited from class android.app.Application.ActivityLifecycleCallbacks
onActivityPostCreated, onActivityPostDestroyed, onActivityPostPaused, onActivityPostResumed, onActivityPostSaveInstanceState, onActivityPostStarted, onActivityPostStopped, onActivityPreCreated, onActivityPreDestroyed, onActivityPrePaused, onActivityPreResumed, onActivityPreSaveInstanceState, onActivityPreStarted, onActivityPreStopped -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
addAppLifecycleListener
Unit addAppLifecycleListener(POBAppStateMonitor.POBAppLifecycleListener listener)
Sets the listener to receive lifecycle events.
- Parameters:
listener- POBApplicationLifecycleListener to receive lifecycle events.
-
removeAppLifecycleListener
Unit removeAppLifecycleListener(POBAppStateMonitor.POBAppLifecycleListener listener)
Removes a listener from receiving lifecycle events.
- Parameters:
listener- The listener to be removed from receiving lifecycle events.
-
onActivityCreated
Unit onActivityCreated(Activity activity, Bundle savedInstanceState)
-
onActivityStarted
Unit onActivityStarted(Activity activity)
Called when an activity is started. If the app is not in the foreground, it notifies the listener that the app is in the foreground. It also resets the activity start timer and removes any pending handler callbacks.
-
onActivityResumed
Unit onActivityResumed(Activity activity)
-
onActivityPaused
Unit onActivityPaused(Activity activity)
-
onActivityStopped
Unit onActivityStopped(Activity activity)
This lifecycle callback posts a delayed runnable to check if the app is in the background. If the app remains inactive which means no onActivityStarted callback for more than FOREGROUND_DELAY duration, it notifies the listener that the app is in the background.
-
onActivitySaveInstanceState
Unit onActivitySaveInstanceState(Activity activity, Bundle outState)
-
onActivityDestroyed
Unit onActivityDestroyed(Activity activity)
-
getInstance
final static POBAppStateMonitor getInstance(Application application)
Returns the singleton instance of the POBAppStateMonitor. If the instance is not already created, it initializes a new instance.
- Parameters:
application- The application instance to register lifecycle callbacks.- Returns:
The singleton instance of POBAppStateMonitor.
-
-
-
-