What's the difference if I call System.exit()
vs. killProcess()
.
I am interested in difference only
I dont think There is any difference. although with System.exit(), you should call runFinalizersOnExit first
What should we use?
No one, read this Is quitting an application frowned upon?
It looks like System.exit() is just as good in every respect as kill -- but much simpler and less dependent on other things.
Some have suggested that runFinalizersOnExit be set but according to the docs that is considered unsafe and is phased out as of 1.0 -- so I guess ignore that part.
Contrary to other suggestions, finish() does not end the Linux process which is running the app and does not free up all the memory used by the app.
Granted, android is designed so that for many cases there's no particular need to actually exit an app (At the cost of a slight pause later, android will kill your old apps when it needs their memory) -- however if you do want for any reason to kill your app System.exit() seems to be the idea way. It shuts down the java virtual machine which is running your app - so all resources, memory, and threads will be completely flushed out.
(Note that you can specify in your manifest file that some threads should run in different linux processes -- in which case System.exit() would probably only kill part of your app - but that's more advanced stuff.)
As a matter of fact, I just ran adb shell ps|grep app
and I see the com.example.android.lunarlander sample app which I haven't run in about a week -- still in memory, still taking up almost 100000 bytes of memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With