delphi xe10 手机程序事件服务操作、退出键操作


本文整理自网络,侵删。

 

//程序事件服务操作
var
  FMXApplicationEventService: IFMXApplicationEventService;
begin
  if TPlatformServices.Current.SupportsPlatformService (IFMXApplicationEventService, IInterface(FMXApplicationEventService)) then 
    FMXApplicationEventService.SetApplicationEventHandler(HandleAppEvent)
  else
     flag := false;
end;

function TForm1.HandleAppEvent(AAppEvent: TApplicationEvent; AContext: TObject)   : boolean; 
begin 
  if flag = false then
    exit;
  case AAppEvent of
    TApplicationEvent.aeEnteredBackground:
      begin
          //当程序后台运行了
      end;
  end;
  Result := true;
end;
 

//退出键操作
procedure TPForm.FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
  Shift: TShiftState);
begin
  if Key = vkHardwareBack then
  begin
    {$IFDEF ANDROID}
    MessageDlg('确认退出吗?', System.UITypes.TMsgDlgType.mtInformation,
    [
      System.UITypes.TMsgDlgBtn.mbYes,
      //System.UITypes.TMsgDlgBtn.mbNo,
      System.UITypes.TMsgDlgBtn.mbCancel
    ], 0, System.UITypes.TMsgDlgBtn.mbCancel,
    procedure(const AResult: TModalResult)
    begin
      if AResult = mrYES then
         MainActivity.finish; { 退出程序 }   // use FMX.Platform.Android
      end);
    {$ENDIF ANDROID}
    //close;
    Key := 0;
    exit;
  end;
end;
复制代码
 

博客园 滔Roy https://www.cnblogs.com/guorongtao 

相关阅读 >>

Delphi 判断一个颜色是否是亮色

Delphi删除文件夹

Delphi firedac 下的 sqlite [9] - 关于排序

tstrings 的用法

Delphi deletedirectory 删除目录下所有文件包括子文件夹下所有文件

Delphi 线程中修改主窗体的控件内容

Delphi截取字符串

Delphi调用百度语音识别服务

Delphi中组件label、edit、tag、memo、richedit

iniocp(小旋风服务套件)

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



打赏

取消

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

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

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

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

评论

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