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

Edijs Kolesnikovičs picture Edijs Kolesnikovičs · Oct 7, 2013 · Viewed 20.2k times · Source

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?

Answer

Marcus Adams picture Marcus Adams · Oct 8, 2013

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.