Application really closed ?

nico78

Active Member
Licensed User
Longtime User
Hello,

I try this program and when i close this app and I go into settings, applications, manage applications, my program still works, is this normal?

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("test5")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
   If userclosed=True Then
      ToastMessageShow("Fermeture du programme",True)
   End If 

End Sub


Sub Activity_KeyPress(KeyCode As Int) As Boolean
   Dim Answ As Int
   Select KeyCode
      Case KeyCodes.KEYCODE_BACK
         Answ = Msgbox2("Voulez-vous vraiment quitter le programme ?", "A T T E N T I O N", "Oui", "", "Non", Null) 
         If Answ = DialogResponse.POSITIVE Then
            Return False 'retourner false pour autoriser la fermeture du programme
         Else
            Return True 'retourner true pour empêcher la fermeture du programme
         End If
   End Select
End Sub
 
Last edited:

Kevin

Well-Known Member
Licensed User
Longtime User
That's the way Android works. You can force the app to actually close by using the code below. This is what I prefer, but there are different schools of thought on whether or not you should kill your own app.

B4X:
Sub Activity_Pause (UserClosed As Boolean)

  If UserClosed = True Then
     ' Do whatever
     ' ....
     ExitApplication ' Kill the app
  End If
 
End Sub
 
Upvote 0

lagore

Active Member
Licensed User
Longtime User
This is standard life cycle for android ( if you have not read the guide to android life cycle both here and on the web it is worth reading) when you either 'back' out of your app, hit 'home', launch another app or use activity.finish your app is not killed in the normal sense it is pushed to the background but is still resident in memory, the OS will decide when to kill it off based on memory requirements. EXITAPPLICATION can be used to kill the app but not advised to use, it is recommended to let android decide. If you use the debugger while your app is running keep an eye on the logs tab, it gives a good idea on what state the program is in, watch for 'userclosed' & 'isfirst' close your program relaunch it, launch another program then relaunch you program. This was the most difficult aspect of android for me to get my head around after being used to writing VB programs for PC's.
Edward
 
Upvote 0

nico78

Active Member
Licensed User
Longtime User
Thank you for your advice, but it remains mysterious to keep in memory a program that has been closed.
 
Upvote 0

ZJP

Active Member
Licensed User
Longtime User
Thank you for your advice, but it remains mysterious to keep in memory a program that has been closed.

Yes, staying in memory but not working. The program will restart quickly if requested.

JP
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
Thank you for your advice, but it remains mysterious to keep in memory a program that has been closed.

Why? If the memory isn't needed by other programs, why should the system spend time writing zeros to the memory where the old program was?
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
I think most (if not all) modern operating systems cache recently used applications in memory where possible to improve any subsequent reloading time of that application.

Android is no different.

I don't hear of any Window users frantically trying to unload cached application from memory but for some reason many Android users seem to think memory used to cache applications is wasted and want to reclaim it.

The operating system will do a better job of judging when cached applications are using memory required by other applications and then unload the cached application.

Martin.
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
But, since people expect it, it might be nice to do so as a feature?


Besides, on my phone I think i've seen it not working; when i try to play a video (not with b4a) i'm told this video can't play, then i press play again and this time it plays. So I'm assuming there is memory freed during the first 'error'
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
But, since people expect it, it might be nice to do so as a feature?

That's kind of why I close my own app as well (if the user backs out). I think most people don't realize that there really is no harm in it staying in the background (and I'll admit, when I first got my EVO I didn't understand it either).

People tend to see it as 'wasting their battery', whether it really does anything in the background or not, which some of us now know isn't true unless there is some kind of service or something doing other things in the background, at least from what I understand.

On the other hand, if I'm not mistaken, the B4A Bridge app closes itself if you disable it then back out, no?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
On the other hand, if I'm not mistaken, the B4A Bridge app closes itself if you disable it then back out, no?
No. The service is moved to the foreground when the bridge is listening for connections. When you disable it is removed from the foreground (this causes the notification icon to disappear).
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…