我该如何处理后退按钮preSS的(德尔福)Android应用程序? [英] How do I handle a back-button press in a (Delphi) Android app?

查看:132
本文介绍了我该如何处理后退按钮preSS的(德尔福)Android应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能让我的Andr​​oid应用程序反应后退按钮?

How can I make my Android app react to the back-button?

有什么作为高层次的VCL的TApplicationEvents来处理它,或者我需要潜水深入到这里的低级别的Andr​​oid特有的东西?

Is there something as high-level VCL's TApplicationEvents to handle it, or do I need to dive deep into low-level Android-specific stuff here?

目前,大多数的演示应用程序有一个屏幕上的后退按钮返回到previous屏幕。 $ P $总是pssing的psysical按钮似乎退出程序,而在某些情况下,它会导致访问冲突

Right now, most of the demo applications have an on-screen back button to go back to a previous screen. Pressing the psysical button always seems to quit the app, and in some situations it results in an access violation.

推荐答案

在表单的 OnKey ... 活动时,参数 vkHardwareBack 在Android上。例如:

In the form's OnKey... events, the Key parameter is vkHardwareBack on Android. For example:

uses
  FMX.Platform, FMX.VirtualKeyboard;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
var
  FService : IFMXVirtualKeyboardService;
begin
  if Key = vkHardwareBack then
  begin
    TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardService, IInterface(FService));
    if (FService <> nil) and (vksVisible in FService.VirtualKeyBoardState) then
    begin
      // Back button pressed, keyboard visible, so do nothing...
    end else
    begin
      // Back button pressed, keyboard not visible or not supported on this platform, lets exit the app...
      if MessageDlg('Exit Application?', TMsgDlgType.mtConfirmation, [TMsgDlgBtn.mbOK, TMsgDlgBtn.mbCancel], -1) = mrOK then
      begin
        // Exit application here...
      end else
      begin
        // They changed their mind, so ignore the Back button press...
        Key := 0;
      end;
    end;
  end
  ...
end;

这篇关于我该如何处理后退按钮preSS的(德尔福)Android应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆