Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey, Delphi Android, Delphi IOS

Handle Android And IOS Lifecycle Events In Delphi XE5 Firemonkey

| Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOS

Delphi Firemonkey Android IOS Application Lifecycle | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSUnlike standard Delphi desktop applications, the lifecycle of a mobile app is different and more complex. Also, the lifecycle of an Android application is slightly different than that of an iOS application. On both Android and iOS mobile devices, an application runs either in the foreground or in the background. For example, when a phone call arrives or when the user opens another application on the device, your application will go to the background. As a programmer, you may need to respond to these life cycle events. For example, you may need to save your current application state when your application is sent to the background or repaint the screen when moving back to the foreground. Using Delphi XE5, it is possible to use the same source code and compile your mobile application for Android and iOS. Although there are differences in their architectures, FireMonkey contains the “FMX.Platform” unit, which contains an interface definition of a “IFMXApplicationEventService” that makes it possible register an event handler to receive application lifecycle events for both platforms. Delphi XE5 version:

function TForm11.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
begin
  case AAppEvent of
    aeFinishedLaunching: Log('Finished Launching');
    aeBecameActive: Log('Became Active');
    aeWillBecomeInactive: Log('Will Become Inactive');
    aeEnteredBackground: Log('Entered Background');
    aeWillBecomeForeground: Log('Will Become Foreground');
    aeWillTerminate: Log('Will Terminate');
    aeLowMemory: Log('Low Memory');
    aeTimeChange: Log('Time Change');
    aeOpenURL: Log('Open URL');
  end;
  Result := True;
end;


Update: Delphi XE6 and Delphi XE7 version:

function TForm11.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
begin
  case AAppEvent of
    FinishedLaunching: Log('Finished Launching');
    BecameActive: Log('Became Active');
    WillBecomeInactive: Log('Will Become Inactive');
    EnteredBackground: Log('Entered Background');
    WillBecomeForeground: Log('Will Become Foreground');
    WillTerminate: Log('Will Terminate');
    LowMemory: Log('Low Memory');
    TimeChange: Log('Time Change');
    OpenURL: Log('Open URL');
  end;
  Result := True;
end;


Stop by Embarcadero’s Delphi Programming blog and review the full code and download the simple demo

Exit mobile version