Interface LifecycleService

  • All Known Implementing Classes:
    AndroidLifecycleService, DesktopLifecycleService, DummyLifecycleService, IOSLifecycleService

    public interface LifecycleService
    The lifecycle service provides a way to listen for events when the application is being paused (put in the background) and resumed (brought back to the foreground). It also allows the developer to properly shutdown the application.

    Example

     LifecycleService.create().ifPresent(service -> {
          service.addListener(LifecycleEvent.PAUSE, () -> System.out.println("Application is paused."));
          service.addListener(LifecycleEvent.RESUME, () -> System.out.println("Application is resumed."));
      });

    Android Configuration: none

    iOS Configuration: none

    Since:
    3.0.0
    See Also:
    LifecycleEvent
    • Method Detail

      • addListener

        void addListener​(LifecycleEvent lifecycleEvent,
                         java.lang.Runnable eventHandler)
        Adds a life cycle event listener to the native platform, to be notified of LifecycleEvent events.
        Parameters:
        lifecycleEvent - The type of event to listen for.
        eventHandler - The event handler that will be called when the event fires.
      • removeListener

        void removeListener​(LifecycleEvent lifecycleEvent,
                            java.lang.Runnable eventHandler)
        Removes a previously installed event handler. If no such event handler is found, this method is a no-op.
        Parameters:
        lifecycleEvent - The type of event that was being listened to.
        eventHandler - The event handler that should be removed.
      • shutdown

        void shutdown()
        Initiates the process of shutting down the application that called this method. This removes the need to perform any platform-specific shutdown routines.