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

夙愿已清 提交于 2019-12-28 04:26:14

问题


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?


回答1:


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.




回答2:


uses 
  FMX.Platform.Android;

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



回答3:


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);



回答4:


Calling Halt also closes the application.



来源:https://stackoverflow.com/questions/19234502/how-to-close-android-app-in-delphi-xe5-firemonkey-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!