Delphi XE5 android 捕获几个事件
2022-10-07 08:53:16 作者:admin
本文整理自网络,侵删。
以下代码能监控到以下几个事件:
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 ofTApplicationEvent.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.
猜你喜欢
联络方式:
400-123-789
邮箱:xiachao@163.com
Q Q:12345678
微信公众号
微信二维码