Delphi XE5 android 捕获几个事件


本文整理自网络,侵删。

 以下代码能监控到以下几个事件:
FinishedLaunching
BecameActive
WillBecomeInactive
EnteredBackground
WillBecomeForeground
WillTerminate
LowMemory
TimeChange
OpenURL


unit Unit11;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts,
  FMX.Memo, FMX.Platform, FMX.StdCtrls;

type
  TForm11 = class(TForm)
    Memo1: TMemo;
    ToolBar1: TToolBar;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
  private
    procedure Log(s: string);
  public
    function HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject): Boolean;
  end;

var
  Form11: TForm11;

implementation

{$R *.fmx}

{ TForm11 }

procedure TForm11.FormCreate(Sender: TObject);
var aFMXApplicationEventService: IFMXApplicationEventService;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXApplicationEventService, IInterface(aFMXApplicationEventService)) then
    aFMXApplicationEventService.SetApplicationEventHandler(HandleAppEvent)
  else
    Log('Application Event Service is not supported.');
end;

function TForm11.HandleAppEvent(AAppEvent: TApplicationEvent;AContext: TObject): Boolean;
begin
  case AAppEvent of
TApplicationEvent.aeFinishedLaunching: Log('Finished Launching');
TApplicationEvent.aeBecameActive: Log('Became Active');
TApplicationEvent.aeWillBecomeInactive: Log('Will Become Inactive');
TApplicationEvent.aeEnteredBackground: Log('Entered Background');
TApplicationEvent.aeWillBecomeForeground: Log('Will Become Foreground');
TApplicationEvent.aeWillTerminate: Log('Will Terminate');
TApplicationEvent.aeLowMemory: Log('Low Memory');
TApplicationEvent.aeTimeChange: Log('Time Change');
TApplicationEvent.aeOpenURL: Log('Open URL');
  end;
  Result := True;
end;


procedure TForm11.Log(s: string);
begin
  Memo1.Lines.Add(TimeToStr(Now) + ': ' + s);
end;

end.


相关阅读 >>

Delphi 线程同步(线程安全)

Delphi fmx手机app,如何下载网站图片而不卡界面

Delphi 编写服务程序的几点总结

winapi 字符及字符串函数(4): charupperbuff - 把缓冲区中指定数目的字符转大写

Delphi 在电脑屏幕上显示图片

Delphi listview 与数据库连接

Delphi 如何快速读取文本文件

Delphi deletefile 删除文件

Delphi 资源文件管理 resources and images

Delphi 调用外部 dll 中的函数(1. 早绑定)

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



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...