-
- 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 Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addListener(LifecycleEvent lifecycleEvent, java.lang.Runnable eventHandler)
Adds a life cycle event listener to the native platform, to be notified ofLifecycleEvent
events.static java.util.Optional<LifecycleService>
create()
Returns an instance ofLifecycleService
.void
removeListener(LifecycleEvent lifecycleEvent, java.lang.Runnable eventHandler)
Removes a previously installed event handler.void
shutdown()
Initiates the process of shutting down the application that called this method.
-
-
-
Method Detail
-
create
static java.util.Optional<LifecycleService> create()
Returns an instance ofLifecycleService
.- Returns:
- An instance of
LifecycleService
.
-
addListener
void addListener(LifecycleEvent lifecycleEvent, java.lang.Runnable eventHandler)
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
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.
-
-