I tried:
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
Shift: TShiftState);
begin
if Key = vkHardwareBack then begin
Key := 0;
Form1.WindowState := TWindowState.wsMinimized; // Also tried Application.MainForm
end;
end;
But when you hit the first time the screen gets black, when you hit the second time the app closes. How to avoid this?
The android way would be to switch to the desktop instead of trying to minimize your app. There are at least two ways to achieve this:
First possibility is to call:
MainActivity.movetasktoback(true);
Second possibility is:
var
Intent: JIntent;
begin
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_MAIN);
Intent.addCategory(TJIntent.JavaClass.CATEGORY_HOME);
tandroidhelper.activity.startActivity(Intent);
However I noticed that under Delphi both ways do seem to lead to a black screen app when reactivated.