当应用程序本身变为活动状态或进入后台时如何获取事件。使用IFMXApplicationEventService获取状态更改的通知。
uses
FMX.Platform;
type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
{ private 宣言 }
///
/// アプリケーションの状態変化イベントを受け取る関数
///
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的返回值用于什么。.. ..
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.040763139724731 seconds