How to close android app in Delphi-XE5 Firemonkey application?
21,395
Solution 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.
Solution 2
uses
FMX.Platform.Android;
procedure TForm2.SpeedButton1Click(Sender: TObject);
begin
MainActivity.finish;
end;
Solution 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);
Author by
Edijs Kolesnikovičs
I love programing! Do not hesitate and ask me to code something. No web stuff tho. I am Delphi programmer that is interested in Java or C++
Updated on April 17, 2020Comments
-
Edijs Kolesnikovičs about 4 years
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?
-
Marcus Adams over 10 yearsWith Halt, the execution path immediately stops. Your finally in try...finally statements don't get called. Your form's OnClose won't be called, etc.
-
Oussama Al Rifai over 10 yearsThanks Marcus. By the way, I tried SharedActivity.finish in an application where I use TGuestureManager, it didn't close the application. it is still in the running application list. moreover when I try to activate it it hangs. Am I missing something? When I run it in debugger mode. I get exception in TGuestureManger.Notification proceedure in 1st line.
-
Marcus Adams over 10 yearsDo you have any other activities running?
-
Oussama Al Rifai over 10 yearsI new to android.. I call another window and then I close it... does that mean that it is still open? and if yes, how should I close it?
-
naXa stands with Ukraine about 10 yearsIt's a brutal way to kill your application.
-
Machado almost 10 yearsMake sure FMX.Platform.Android is properly declared.
-
Remy Lebeau over 9 yearsOr the
FMX.TApplication.Terminate()
method, which also finishes the Activity on Android (and does the equivalent action on other platforms). -
Remy Lebeau over 9 yearsDid you try
FMX.Application.Terminate()
yet? -
Jerry Dodge over 9 years@Remy On
XE7
for me,Application.Terminate
returns numerous error messages in the IDE when debugging on an android device. -
Remy Lebeau over 9 years@JerryDodge: Such as?
-
Jerry Dodge over 9 years@Remy Such as access violations (3 of them) - not seeking help, just a note. Not in front of it at the moment.
-
TiagoTecchio about 7 yearsYes, I tried. Not working... Even with Berlin Update 2, apps running in Samsung devices don't close properly. It's annoying...