Delphi FMX检查应用程序状态更改

2022-12-28 09:19:16 作者:admin

本文整理自网络,侵删。

 

当应用程序本身变为活动状态或进入后台时如何获取事件。使用IFMXApplicationEventService获取状态更改的通知。

uses

  FMX.Platform;

 

type

  TForm1 = class(TForm)

    Memo1: TMemo;

    procedure FormCreate(Sender: TObject);

  private

    { private 宣言 }

    /// <summary>

    ///  アプリケ?`ションの状?B?浠?イベントを受け取る?v数

    /// </summary>

    function AppEventHandle(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;

  end;

 

procedure TForm1.FormCreate(Sender: TObject);

var

  service: IFMXApplicationEventService;

begin

  if TPlatformServices.Current.SupportsPlatformService(

      IFMXApplicationEventService, service) then

  begin

    service.SetApplicationEventHandler(AppEventHandle);

  end;

end;

 

function TForm1.AppEventHandle(AAppEvent: TApplicationEvent;

  AContext: TObject): Boolean;

begin

  Result := True;

 

  case AAppEvent of

    TApplicationEvent.FinishedLaunching: begin

      Memo1.Lines.Add('应用启动'); //delphitop.com

    end;

    TApplicationEvent.BecameActive: begin

      Memo1.Lines.Add('应用程序具有焦点');

    end;

    TApplicationEvent.WillBecomeInactive: begin

      Memo1.Lines.Add('焦点超出本申请的');

    end;

    TApplicationEvent.EnteredBackground: begin

      Memo1.Lines.Add('在后台运行的应用程序');

    end;

    TApplicationEvent.WillBecomeForeground: begin

      Memo1.Lines.Add('从背景返回');

    end;

    TApplicationEvent.WillTerminate: begin

      Memo1.Lines.Add('已经完成了应用');

    end;

    TApplicationEvent.LowMemory: begin

      Memo1.Lines.Add('缺少的设备的存储器');

    end;

    TApplicationEvent.TimeChange: begin

      // iOSのみ

      Memo1.Lines.Add('时间的重大变化');

    end;

    TApplicationEvent.OpenURL: begin

      // iOSのみ

      Memo1.Lines.Add('要求应用程序打开一个URL已接收');

    end;

  end;

end;

 

但是,我不确定AppEventHandle的返回值用于什么。.. ..

相关阅读 >>

Delphi tms web core 嵌入js代码

Delphi fmx 绘制非常精确的 时分秒针

Delphi xe6 android 界面皮肤美化 用stylebook

Delphi控件升级

Delphi 根据开始和结束符取得中间字符串

Delphi httpserver 使用方法

Delphi 利用Delphi监视注册表的变化

tclientsocket和tserversocket用法

Delphi date 返回当前的日期

Delphi 获取本地网络连接

更多相关阅读请进入《Delphi》频道 >>



在线咨询 拨打电话