Android Question ExitApplication vs. Activity.Finish

Status
Not open for further replies.

Beja

Expert
Licensed User
Longtime User
It's everywhere that to let the OS kill the app or process is better.. but I didn't read or knew why.. anyone has more info.. what's the risk of exiting the app...etc.
 

LucaMs

Expert
Licensed User
Longtime User
what's the risk of exiting the app
I don't think that can be any risk (or disadvantage) closing explicitly your app (process).

Anyway, simply calling Activity.Finish you don't close the app, you need also to stop all services (and sometimes you don't know which services your app started, because it is possible that a library you added starts some service).
 
Upvote 0

ronell

Well-Known Member
Licensed User
Longtime User
i did try to use exitapplication in my app .. the activity just reset :confused:
so one of the risk maybe , if you force exit/kill the app(services , activity) the os will reset it
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
i did try to use exitapplication in my app .. the activity just reset :confused:
so one of the risk maybe , if you force exit/kill the app(services , activity) the os will reset it

Very interesting. So killing the process will rest the activity. too bad.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The OS will treat your app as if it has crashed when you call ExitApplication. In some cases it will try to restart it automatically.

Another advantage of Activity.Finish is that the os can keep the process running for some time. If the user returns to your app then it will not need to create a new process.

If you are targeting Android 4.1+ (API 16+) then you can use this code to close all activities:
B4X:
Sub CloseActivities
 Dim jo As JavaObject
 jo.InitializeContext
 jo.RunMethod("finishAffinity", Null)
End Sub
 
Upvote 0
Status
Not open for further replies.
Top