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

AndroidAppmethodCode SnippetDelphiFiremonkey

Use Bitmaps In Threads On Android With This Fix For Delphi XE5 Firemonkey

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

Delphi XE5 Firemonkey Android Bitmap Thread | Delphi 11 10 XE8 XE7 XE Seattle Berlin Tokyo Rio Firemonkey Delphi Android Delphi IOSApparently loading a bitmap from a file or a stream from within a thread on Android in Delphi XE5 Firemonkey has a problem. It causes your app to exit completely according to a question and answer on StackOverflow. If you’ve been having problems with bitmaps and threads at all on Android try adding this code fix and see if it takes care of it. The fix involves overriding the EndThreadProc procedure from System.Classes in the OnCreate event of your form. User ioan posted the fix to StackOverflow and Antonio Tortosa from Embarcadero posted the original fix to the Embarcadero forum (see threads here and here). I tested the fix on Android with uImageLoader and it did in fact fix a crash with that class. Override EndThreadProc with the following procedure:
uses
Androidapi.NativeActivity,
Posix.Pthread;

procedure MyEndThreadProc(ExitCode:Integer);
var
PActivity: PANativeActivity;
begin
PActivity := PANativeActivity(System.DelphiActivity);
PActivity^.vm^.DetachCurrentThread(PActivity^.vm);
pthread_exit(ExitCode);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
EndThreadProc := MyEndThreadProc;
end;

Head over and read the full question and answer about bitmaps and threads with Android on StackOverflow.

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

Related posts
DelphiDemoFiremonkeyLinuxOSXShowcaseWindows

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

DelphiFiremonkeyShowcaseUtilityWindows

Unleashing Creativity With Song Writer AI: A Deep Dive

DelphiFiremonkeyShowcaseWindows

How To Build Stable Diffusion Text To Image Prompts

AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

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

2 Comments

Leave a Reply