Edijs Kolesnikovičs
Edijs Kolesnikovičs

Reputation: 1695

How to close android app in Delphi-XE5 Firemonkey application?

I have this piece of code

procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
  msg: String;
begin
  msg := 'Do you really want to exit?';

  if MessageDlg(msg, TMsgDlgType.mtConfirmation,
    [TMsgDlgBtn.mbYes, TMsgDlgBtn.mbNo], 0) = mrNo then
    CanClose := False
  else
    CanClose := True; { FIXME: don't want to work on Android }
end;

It works perfectly on Windows. Application closes if I choose 'Yes'. However, application does NOT close on Android. What I am doing wrong?

Upvotes: 8

Views: 22835

Answers (4)

xJernej
xJernej

Reputation: 194

I tried all combinations.

 - SharedActivity.Finish - NOT WORKING FOR ME
 - MainActivity.Finish - NOT WORKING FOR ME
 - Application.MainForm.DisposeOf - NOT WORKING FOR ME

This is works for me :

 FreeAndNil(Application);

Upvotes: 1

Helios
Helios

Reputation: 71

uses 
  FMX.Platform.Android;

procedure TForm2.SpeedButton1Click(Sender: TObject); 
begin 
  MainActivity.finish; 
end; 

Upvotes: 7

Oussama Al Rifai
Oussama Al Rifai

Reputation: 333

Calling Halt also closes the application.

Upvotes: 0

Marcus Adams
Marcus Adams

Reputation: 53870

Having the application close when the last form is closed is a Windows thing. An Android app will keep running.

To close the app on Android, call SharedActivity.finish from the FMX.Helpers.Android unit.

Upvotes: 13

Related Questions