- 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:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(LifecycleEvent lifecycleEvent, Runnable eventHandler) Adds a life cycle event listener to the native platform, to be notified ofLifecycleEvent
events.static Optional<LifecycleService>
create()
Returns an instance ofLifecycleService
.void
removeListener
(LifecycleEvent lifecycleEvent, Runnable eventHandler) Removes a previously installed event handler.void
shutdown()
Initiates the process of shutting down the application that called this method.
-
Method Details
-
create
Returns an instance ofLifecycleService
.- Returns:
- An instance of
LifecycleService
.
-
addListener
Adds a life cycle event listener to the native platform, to be notified ofLifecycleEvent
events.- Parameters:
lifecycleEvent
- The type of event to listen for.eventHandler
- The event handler that will be called when the event fires.
-
removeListener
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.
-