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.


     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

    See Also:
    • 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.
        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.
        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.