Android Question Final closing of an app

AlpVir

Well-Known Member
Licensed User
Longtime User
Question: is ' normal that the app is still present in :
- Settings
- Applications
- Manage application
- Downloaded
and then there is the possibility to do a "Force Stop" (the button "Force Stop" is on the left of button "Uninstall") ?

I read what he says Agraham :
Activities consume no CPU time if they are not displayed , and indeed may not exist at all if Android wanted to reclaim Their memory . Services can run in the background but can be destroyed by Android Also Unless You Have Invoked StartForeground Which Means That Android will attempt to keep it running .

This is the code that I use to close my app (with many Activity)
B4X:
Sub Activity_Pause (UserClosed As Boolean)
   If FlagEndOfApp = True Then 
       Log("- debug Close app")
       StopService("")
       GPS2.GPS1.Stop  
       StopService("GPS2")   ' stop the service  [ StartServiceAt("GPS2" , DateTime.Now  + Ms , False) ]
       CancelScheduledService (GPS2)
       StopService("httputils2service")
       Main.TW.Flush
       Main.TW.Close     ' close TextWriter
       Main.dbIAH.Close  ' close db sqlite
   End If
End Sub

Apparently everything seems OK but if you relaunch the app it has an unexpected behavior, and I understand that the app was just ... sleeping .
This is not satisfactory !
If, however, I do a "Force Stop" and restart the app works just the way I want .
I came to the conclusion that I have to force a shutdown of the app or (better) to improve the code with which I finish the app.
How could I make ?
Thanks in advance.
 

stevel05

Expert
Licensed User
Longtime User
What is the 'unexpected behaviour'? perhaps there is something you're not shutting down. We need some more information before suggesting solutions.
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
It preserves the value of certain variables (perhaps all). Particularly those that affect the appearance of the app. Just as if the app was dormant and is awakened to return to the state it was.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
It preserves the value of certain variables (perhaps all). Particularly those that affect the appearance of the app. Just as if the app was dormant and is awakened to return to the state it was.

I give it a look, but in the Activity_Pause sub you don't check User_Closed and do not use ExitApplication ...?

Ho dato solo un'occhiata, ma nella Activity_Pause non controlli UserClosed e non usi ExitApplication...?

(si, usi quel flag, ma...!)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I confess I do not know what is the parameter UserClosed of Activity_Pause.


It's very simple: UserClosed is true only if the user "clicks" back (or your own btnClose wich "executes" ExitApplication).
Maremma inglese, hehehe

E' semplice, UserClosed diventa vera solo se l'utente esce dalla tua app usando il "tasto" Back, se non hai previsto un tuo tasto per uscire, che magari lancia una sub di chiusura che contenga, alla fine, ExitApplication.

But you see some thread or service of your app still running?
Ma vedi qualche thread o servizio della tua app ancora attiva, dopo la chiusura? E' questo il problema? Da quel poco che vedo, i servizi li chiudi. Forse ti manca solo l'ExitApplication
 
Upvote 0

AlpVir

Well-Known Member
Licensed User
Longtime User
Yes, I have read the documentation and it seems to have applied correctly.
Report below 3 pieces of code
Region Activity Attributes :
B4X:
# SupportedOrientations: portrait
All activity have :
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
  If KeyCode = KeyCodes.KEYCODE_BACK Then Return True
end Sub
The end of the last activity is launched by :
B4X:
sub ButtonEnd_click
  FlagFineEffettiva = False
  Activity.Finish
end Sub

@LucaMs : ExitApplication produce un errore. I servizi sono tutti correttamente chiusi. E' solo l'app che è aperta ed invisibile.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Yes, I have read the documentation and it seems to have applied correctly.
Report below 3 pieces of code
Region Activity Attributes :
B4X:
# SupportedOrientations: portrait
All activity have :
B4X:
Sub Activity_KeyPress (KeyCode As Int) As Boolean
  If KeyCode = KeyCodes.KEYCODE_BACK Then Return True
end Sub
The end of the last activity is launched by :
B4X:
sub ButtonEnd_click
  FlagFineEffettiva = False
  Activity.Finish
end Sub

@LucaMs : ExitApplication produce un errore. I servizi sono tutti correttamente chiusi. E' solo l'app che è aperta ed invisibile.


SupportedOrientations? don't matter (chissene, hehehe)

This don't works well: on a second click on Back, the app is closed.
B4X:
[CODE]Sub Activity_KeyPress (KeyCode As Int) As Boolean
  If KeyCode = KeyCodes.KEYCODE_BACK Then Return True
end Sub
[/CODE]

There is an Erel's sample for this issue... wait a moment or search it :)

(Here)

You should use ExitApplication in a sub of your Main Activity.
 
Upvote 0
Top