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

at dalvik.system.NativeStart.main(Native Method)
libjpeg error 105 < Ss=%d, Se=%d, Ah=%d, Al=%d> from allocPixelRef [2832 2124]
--- decoder->decode returned false
Shutting down VM
threadid=1: thread exiting with uncaught exception (group=0x4016b760)
FATAL EXCEPTION: main
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:549)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize2(CanvasWrapper.java:493)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:486)
at WDROrder.Program.maintenance._activity_create(maintenance.java:227)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:105)
at WDROrder.Program.maintenance.afterFirstLayout(maintenance.java:84)
at WDROrder.Program.maintenance.access$100(maintenance.java:16)
at WDROrder.Program.maintenance$WaitForLayout.run(maintenance.java:72)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4025)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Force finishing activity WDROrder.Program/.maintenance
Force finishing activity WDROrder.Program/.main
Activity pause timeout for ActivityRecord{40c081f0 WDROrder.Program/.maintenance}
GC_EXPLICIT freed 21K, 6% free 6246K/6595K, paused 6ms+2ms
Activity destroy timeout for ActivityRecord{40c1f4a0 WDROrder.Program/.main}
Activity destroy timeout for ActivityRecord{40c081f0 WDROrder.Program/.maintenance}
GC_CONCURRENT freed 442K, 10% free 6474K/7175K, paused 6ms+2ms
Setting rotation to 2, animFlags=0
Config changed: { scale=1.0 imsi=0/0 loc=en_SG touch=3 keys=1/1/2 nav=1/2 orien=L layout=0x10000014 uiMode=0x11 seq=4}
GC_CONCURRENT freed 5915K, 42% free 10386K/17735K, paused 2ms+3ms
GC_CONCURRENT freed 1033K, 40% free 10642K/17735K, paused 3ms+2ms
GC_CONCURRENT freed 1139K, 39% free 10950K/17735K, paused 2ms+4ms

How can i monitor memory usage?

Thanks
 
Upvote 0
Top