Home > Blockchain >  Delphi Android service crash when add FMX.types declaration
Delphi Android service crash when add FMX.types declaration

Time:10-27

I have Delphi 11 Alexandria, and I've recreated the simple demo to "make an Android Service".

It works fine when I run it on my Android phone, so now I want to add more complexity to the service by adding a TTimer component to the TDataModule, but when I add the TTimer then the app crashes when started.

Then I remove the TTimer component from the TDataModule and run again, but the app crashes again.

If I then remove the declaration of FMX.Types from the service (it was added when I put the TTimer on the TDataModule), then the app run fine again.

Why is it not possible to add FMX.Types into an Android service?

Is it not possible to use TTimer in an Android service?

CodePudding user response:

As @DalijaPrasnikar mentioned in a comment, this is a known bug:

RSP-17857: Android service applications crash if FMX.Types unit is included

The FMX.Types unit doesn't work in a service, as its initialization is trying to access a nil pointer at runtime (specifically, a global named DelphiActivity, which is not set for a service, only for an app).

To use a timer in a service, try this workaround code:

https://github.com/DelphiWorlds/KastriFree/blob/master/Demos/AndroidLocation/Common/LS.AndroidTimer.pas

  • Related