Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!


Allow Apps To Run In Background Under FireMonkey In Delphi 10 Berlin On IOS

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

Delphi 10 Berlin IOS Background App FireMonkey | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSDeveloper David Nottage proposes a nice solution to keeping your applications to run in the background on iOS. On iOS as well as on Android, it is the system that decides when to terminate an app for very specific reasons (i.e. memory starvation). For this particular reason, the onClose event of the app might not trigger, since the system decides to immediately kill the application. Thus, you should never place important code in this event, since it will not execute and even worse you could cause memory leaks if you try to free the memory in the onClose event and this event is not fired. Suspended applications receive no notification when they are terminated unlike the applications that run in the background and are not in the suspended state. In this case, the system calls applicationWillTerminate before the actual onClose event. In Delphi, in the case of UIApplication, two important methods have been left out:

function beginBackgroundTaskWithExpirationHandler(handler: TBackgroundTaskHandler): UIBackgroundTaskIdentifier; cdecl;
procedure endBackgroundTask(identifier: UIBackgroundTaskIdentifier); cdecl;

The demo, wraps the two methods and provides easy and convenient integration. The implementation applies to Delphi 10 Berlin with FireMonkey. Here is a small sample of the demo implementation, just to give an idea and stir your interest to study it in more detail. This method is not related to UIBackgroundModes.

function TBackgroundTaskManager.Start: Boolean;
  FTaskID := SharedApplication.beginBackgroundTaskWithExpirationHandler(DoExpiry);
  Result := IsValidTask;

procedure TBackgroundTaskManager.Stop;
  if IsValidTask then

Head over and check out the demo for IOS Background Applications for Delphi Berlin with FireMonkey.

Mirror: Download the background IOS demo for Delphi 10 Berlin.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

Related posts

AutoBlogAI: FireMonkey Client To Leverage LLMs And Generative AI For Blogging


Unleashing Creativity With Song Writer AI: A Deep Dive


How To Build Stable Diffusion Text To Image Prompts


FireMonkey 10.4.2 Features Updated iOS 14, Android 11, And macOS 11 Support Plus Hundreds Of Fixes

Sign up for our Newsletter and
stay informed

1 Comment

Leave a Reply