Delphi XE5 android 捕获几个事件

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
    aeFinishedLaunching: Log(Finished Launching);
    aeBecameActive: Log(Became Active);
    aeWillBecomeInactive: Log(Will Become Inactive);
    aeEnteredBackground: Log(Entered Background);
    aeWillBecomeForeground: Log(Will Become Foreground);
    aeWillTerminate: Log(Will Terminate);
    aeLowMemory: Log(Low Memory);
    aeTimeChange: Log(Time Change);
    aeOpenURL: Log(Open URL);
  end;
  Result := True;
end;

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

end.
View Code

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。