0% found this document useful (0 votes)
329 views1 page

How Do I Handle A Back-Button Press in A (Delphi) Android App

The document discusses how to handle the back button press in a Delphi Android app. It shows code that checks if the back button was pressed by checking if the Key parameter is vkHardwareBack. It then checks if the virtual keyboard is visible using the IFMXVirtualKeyboardService. If the keyboard is not visible, it prompts the user to confirm if they want to exit the app, and exits if they confirm.

Uploaded by

Arja'un Tea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
329 views1 page

How Do I Handle A Back-Button Press in A (Delphi) Android App

The document discusses how to handle the back button press in a Delphi Android app. It shows code that checks if the back button was pressed by checking if the Key parameter is vkHardwareBack. It then checks if the virtual keyboard is visible using the IFMXVirtualKeyboardService. If the keyboard is not visible, it prompts the user to confirm if they want to exit the app, and exits if they confirm.

Uploaded by

Arja'un Tea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

How do I handle a back-button press in a (Delphi) Android app

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;

Try this:

uses FMX.Platform,FMX.VirtualKeyboard,FMX.Helpers.Android;

procedure THeaderFooterForm.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
if MessageDlg('Exit Application?', TMsgDlgType.mtConfirmation, [TMsgDlgBtn.mbOK, TMsgDlgBtn.mbCancel], -1) = mrOK then
begin
// Exit application here...
SharedActivity.Finish;
end;
end;
end
else
// Menu button pressed
if Key = sgiUpRightLong then
begin
showmessage('Menu button pressed');
end;
end;

You might also like