Maurício Lima
Maurício Lima

Reputation: 534

How to minimize an Android app on Delphi?

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?

Upvotes: 2

Views: 1133

Answers (1)

Andre Ruebel
Andre Ruebel

Reputation: 564

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.

Upvotes: 5

Related Questions