Firemonkey:如何检测操作系统(Android/iOS)何时关闭



我正在处理Firemonkey(Delphi 10.4(的以下问题:当Android操作系统关闭并且我的应用程序仍在运行时,它不会触发OnCloseQuery、OnClose和OnDestroy事件。有没有办法检测或拦截操作系统关闭事件?当我用方形按钮关闭应用程序时,也会出现同样的问题(也就是说,当我用正方形按钮显示最近打开的应用程序,然后以这种方式关闭应用程序(。

提前谢谢。

我终于从一位TMS客户那里找到了一个解决方案(Ken Randall"Randall_Ken"活动客户。(

uses FMX.Platform;
procedure TMyForm.FormCreate(Sender: TObject);
var
AppEventSvc: IFMXApplicationEventService;
begin
if TPlatformServices.Current.SupportsPlatformService
(IFMXApplicationEventService, IInterface(AppEventSvc)) then
begin
AppEventSvc.SetApplicationEventHandler(AppEvent);
end;
end;
function TMyForm.AppEvent(AAppEvent: TApplicationEvent;
AContext: TObject): Boolean;
begin
if AAppEvent = TApplicationEvent.WillTerminate then
begin
// Do soomething
end;
Result := true;
end;

最新更新