Programmatically FORCE KILL

NJDude

Expert
Licensed User
Longtime User
I'm still learning about programming Android.

Comparing a "desktop" app with an Android app I see a difference, when you close a "desktop" up it STOPS and unloads from memory, but an Android app keeps running until you FORCE STOP; is there a way to write a force stop so you can add an EXIT button and really stop it?
 

TomK

Member
Licensed User
Longtime User
I believe ExitApplication does this, but there must be some downsides to using it. My first instinct would be garbage collection on objects.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
ExitApplication does kill the current process and frees all resources.
However in some cases the OS might restart the process automatically. This usually happens when you have several activities.

In most cases you should not call ExitApplication. Instead you should let Android handle the life cycle of your program.
You can call Activity.Finish to close the current activity.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Thanks Erel for your reply.

So, basically, if you want to be a "good android programmer" you should include an EXIT button in your application which should finish all the activities and then kill the process.

Correct me if I'm wrong but if you don't do what is mentioned above you'll be using the battery unnecessarely and perhaps since the app still running CPU cycles making you device slow.

I'm just trying to understand how the OS runs things.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
if you want to be a "good android programmer" you should include an EXIT button in your application
No, you can leave Android to manage your application.

you'll be using the battery unnecessarely and perhaps since the app still running CPU cycles making you device slow.
No. 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 also be destroyed by Android unless you have invoked StartForeground which means that Android will attempt to keep it running.
 
Upvote 0

Smee

Well-Known Member
Licensed User
Longtime User
My program keeps shutting down with a "force close".
It looks like a memoryy error


How can i monitor memory usage?

Thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…