Process Life Management Gem
Process Life Management Gem
The Process Life Management gem demonstrates how you can respond to various application lifecycle events dispatched by the Lumberyard engine, in order to pause your game, display a modal splash screen, or anything else you may need to do when your application loses/regains focus.
You can access all system-specific events from C++ (even without enabling the Process Life Management gem) by connecting to the appropriate EBus. Lumberyard also generates platform-agnostic events so that you can handle these events for all supported platforms.
Lumberyard Application Lifecycle Events
Lumberyard Application Lifecycle Events | iOS | Android |
---|---|---|
OnApplicationConstrained | applicationWillResignActive | onPause() |
OnApplicationUnconstrained | applicationDidBecomeActive | onResume() |
OnApplicationSuspended | applicationDidEnterBackground | onPause() |
OnApplicationResumed | applicationWillEnterForeground | onResume() |
OnMobileApplicationWillTerminate | applicationWillTerminate | onDestroy() |
OnMobileApplicationLowMemoryWarning | applicationDidReceiveMemoryWarning | onLowMemory() |
As demonstrated in ProcessLifeManagementGem.h\ProcessLifeManagementGem.cpp
, use the following basic steps to receive process lifecycle events in your game.
To receive process lifecycle events in your game
Derive your class from
AzFramework::ApplicationLifecycleEvents::Bus::Handler
(orAzFramework::[Ios|Android|Windows]LifecycleEvents::Bus::Handler
for platform specific events).Override the functions corresponding to the events that you want to override:
void OnApplicationConstrained(Event /lastEvent/) override; void OnApplicationUnconstrained(Event /lastEvent/) override; void OnApplicationSuspended(Event /lastEvent/) override; void OnApplicationResumed(Event /lastEvent/) override
Connect to the event bus when you want to start listening for events. In addition, be sure to disconnect when you no longer want to receive them. Use the following syntax:
ApplicationLifecycleEvents::Bus::Handler::BusConnect(); … ApplicationLifecycleEvents::Bus::Handler::BusDisconnect();