How to close TDialogService.MessageDialog() automatically after a certain time in Delphi FMX on Android?

180 Views Asked by At

I have the following code in Delphi FMX on Android:

TDialogService.MessageDialog('Test Close message', TMsgDlgType.mtInformation,
                  [TMsgDlgBtn.mbOK], TMsgDlgBtn.mbOK, 0, nil);

I need to auto-close TDialogService.MessageDialog after 3 seconds.

I tried Screen.MousePos.SetLocation(x, x) for set a tap to simulate.

1

There are 1 best solutions below

2
Remy Lebeau On

On Android, TDialogService.MessageDialog() simply calls IFMXDialogServiceAsync.MessageDialogAsync() (as Android does not support synchronous dialogs). The default implementation is buried in the TFMXDialogService class in the FMX.Dialogs.Android unit.

You don't have access to the UI dialog it creates, so you can't close it manually. But, what you could do is write your own class that implements the IFMXDialogServiceAsync interface, and then register that class with FMX (you will have to remove the default service first). Then, you can do whatever you want with your dialog implementation. For instance, you could display your own Form that has a timer on it to close the Form.