Class WindowLifecycleHandler

  • All Implemented Interfaces:

    
    public final class WindowLifecycleHandler
    
                        

    Handles window lifecycle events and tracks window visibility state for a given view.

    This class provides a comprehensive solution for monitoring window visibility changes across different Android API levels. It adapts its behavior based on the device's Android version, using direct window visibility observation for Android UDC+ and focus-based polling for older versions. The handler automatically manages the lifecycle of listeners and coroutines to prevent memory leaks.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Flow<Boolean> observeWindowStateChanges() Provides a flow that emits window visibility state changes.
      final Unit destroy() Destroys the lifecycle handler and cleans up all associated resources.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • WindowLifecycleHandler

        WindowLifecycleHandler(Long windowPollingInterval, CoroutineScope coroutineScope, View observableView, InMobiLogger logger)
        Parameters:
        windowPollingInterval - The interval in milliseconds for polling window state on older Android versions
        coroutineScope - The CoroutineScope for managing asynchronous operations
        observableView - The View to observe for window state changes
    • Method Detail

      • observeWindowStateChanges

         final Flow<Boolean> observeWindowStateChanges()

        Provides a flow that emits window visibility state changes.

        Returns:

        A Flow<Boolean> that emits true when the window is visible, false when invisible

      • destroy

         final Unit destroy()

        Destroys the lifecycle handler and cleans up all associated resources.

        This method cancels all ongoing observations, removes listeners, and stops any polling operations to prevent memory leaks and unnecessary processing.