Domanda

How simulate hardware back button press to close application?

I need close the application by code but Application.Terminate, Close, Hide and DisposeOf do not work.

So I thought to simulate hardware back button press to achieve my goal.

È stato utile?

Soluzione

{$IFDEF ANDROID}
    MainActivity.finish;
{$ENDIF}

Altri suggerimenti

To make your application handle when users press the Back button on their Android device, add an event handler to your form for OnKeyUp, and use the following code within your event handler:

if Key = vkHardwareBack then
begin
// Do whatever you want to do here
Key := 0; // Set Key = 0 if you want to prevent the default action
end;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top