本文整理自网络,侵删。
当应用程序本身变为活动状态或进入后台时如何获取事件。使用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 如何把一个exe做为res加入到dll中,并在运行时生成exe文件执行
Delphi api 函数: getcursorpos 与转换
Delphi 如何遍历整个硬盘的各个目录,就像windows的查找功能那样
Delphi extractfileext() 获取文件后缀的函数
更多相关阅读请进入《Delphi》频道 >>