Recent

Author Topic: How to terminate android application?  (Read 4731 times)

Atak_Snajpera

  • New Member
  • *
  • Posts: 12
How to terminate android application?
« on: January 07, 2022, 04:35:09 pm »
Normally for windows application I just use Application.Terminate.

Ps. I tried AndroidModule.Close command but it acts like Hide. Application is still in memory.

loaded

  • Hero Member
  • *****
  • Posts: 825
Re: How to terminate android application?
« Reply #1 on: January 08, 2022, 08:41:27 am »
Hi,

Code: Pascal  [Select][+][-]
  1. procedure TAndroidModule1.jButton1Click(Sender: TObject);
  2. begin
  3.    self.Destroy;
  4.    halt;
  5. end;
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

rsu333

  • Full Member
  • ***
  • Posts: 110
Re: How to terminate android application?
« Reply #2 on: January 09, 2022, 06:27:27 am »
self.close   also work

Atak_Snajpera

  • New Member
  • *
  • Posts: 12
Re: How to terminate android application?
« Reply #3 on: January 09, 2022, 07:57:19 pm »
I Tried both methods and application is still being minimized to background on Android 9.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: How to terminate android application?
« Reply #4 on: January 09, 2022, 08:17:36 pm »
gApp.finish calls java side which in turn calls:
Code: Java  [Select][+][-]
  1. public  void appFinish() {
  2.            activity.finish();
  3.            System.exit(0); //<< ------- fix by jmpessoa
  4. }

Maybe you are after finishAndRemoveTask() which is not exposed in LAMW and you'll need to call it using JNI.

Edit:
Along these lines:
Code: Pascal  [Select][+][-]
  1. var
  2.   jMethodId_finishAndRemoveTask:jmethodID;
  3. begin
  4.  jMethodId_finishAndRemoveTask := Get_jMethodID( Get_jClassLocalRef('android/app/Activity'), 'finishAndRemoveTask', '()V');
  5.   Call_jVoidMethod(gApp.Jni.jActivity,jMethodId_finishAndRemoveTask);
« Last Edit: January 09, 2022, 09:30:07 pm by engkin »

Atak_Snajpera

  • New Member
  • *
  • Posts: 12
Re: How to terminate android application?
« Reply #5 on: January 10, 2022, 01:35:03 pm »
gApp.finish still sends my application to background. I give up at this point... 

my code
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Form1RequestPermissionResult(Sender: TObject;requestCode: integer; manifestPermission: string;grantResult: TManifestPermissionResult);
  2. begin
  3.  
  4.      if requestCode=1 then
  5.      begin
  6.           if manifestPermission='android.permission.ACCESS_FINE_LOCATION' then
  7.           begin
  8.                if grantResult=PERMISSION_GRANTED then
  9.                begin
  10.                     ShowMessage('Success! ['+manifestPermission+'] Permission grant!!! ' );
  11.                     StartWorkerThread;
  12.                end
  13.                else
  14.                begin
  15.                     jModalDialog1.SetDialogTitle('Information');
  16.                     jModalDialog1.SetDialogMessage('Application can not work without requested permission!');
  17.                     jModalDialog1.TitleFontSize:=12;
  18.                     jModalDialog1.CaptionOK:='Close';
  19.                     jModalDialog1.ShowMessage(Self.PackageName);
  20.                     gApp.Finish();
  21.                end;
  22.           end;                  
  23. end;
« Last Edit: January 10, 2022, 01:37:56 pm by Atak_Snajpera »

Seenkao

  • Hero Member
  • *****
  • Posts: 550
    • New ZenGL.
Re: How to terminate android application?
« Reply #6 on: January 10, 2022, 02:37:21 pm »
Разве у приложения на Android есть полная возможность себя закрывать? Разве не занимается этим сама система Android?

Было бы интересно, откуда вы узнали, что приложение на Android может быть полностью выгружено из памяти самостоятельно.

google translate:
Does an Android application have complete ability to shut itself down? Isn't Android itself doing this?

It would be interesting how did you know that an Android application can be completely unloaded from memory on its own.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

loaded

  • Hero Member
  • *****
  • Posts: 825
Re: How to terminate android application?
« Reply #7 on: January 10, 2022, 05:37:40 pm »
gApp.finish still sends my application to background. I give up at this point... 

No, definitely don't give up!!!  ;D
I thought its purpose was to close the app. In addition, if you want to delete the last used ones, you need to do;
Add the following statement inside the activity block in the AndroidManifest.xml file.
Code: Pascal  [Select][+][-]
  1. android:autoRemoveFromRecents="true"

« Last Edit: January 10, 2022, 06:33:31 pm by loaded »
Check out  loaded on Strava
https://www.strava.com/athletes/109391137

 

TinyPortal © 2005-2018