19 March 2014

How to terminate program in Android?

This blog entry has 2 parts.
1) How to close your own application in Android.
2) My opinion about program termination in Android.

1) How to close your own application in Android.
There are few solutions that DO NOT WORK or THEY DO DIFFERENT THING,BUT  DO NOT CLOSE APPLICATION or  they are not perform by OS as they are magically ignored.

finish(); - this closed activity,but not program (even if none activity left in stack).

moveTaskToBack (true) (documentation on developer.android.com) - it doesn't work as this method is for "move the task containing this activity to the back of the activity stack".


What doesn't work:

This is best way to attempt program to commit suicide :

  android.os.Process.killProcess(android.os.Process.myPid());

Read more about killing process here:(http://stackoverflow.com/questions/2092951/how-to-close-android-application). It works more-less .It works,when program is run in once process .If is multiprocess,then thing get more weird.Make sure,that before you Kill app close all stuff that was turn on by your app (like Bluetooth),there was few weird problems mentioned on some forums about it.

2) My opinion about program termination in Android.

Dave Webb and many more people including experts  said "The Android OS handles memory management and processes and so on so my advice is just let Android worry about this for you."
Making assumption that It does right is wrong.(It does amazing job,but it struggles in weird cases,which could be avoided)

REMEMBER! I am not a expert but I disagree with these opinions.
I believe,that application should have ability   to commit suicide,because..
  • It releases resources,that can be used by other application quicker .
  • It reduces battery consumption as some 'homeless application' like to work very hard in background 
  • It prevents Android  from panic mode when it stops response  or works like turtle due lack of free resources. 

I understand ,why any app can be 'killed' any time by OS,but I believe author should have ability to decide,is his application should stays in memory or be wiped out.



Sources:
http://stackoverflow.com/questions/2042222/close-application-and-launch-home-screen-on-android
http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon
http://stackoverflow.com/questions/2092951/how-to-close-android-application
http://android-developers.blogspot.in/2010/04/multitasking-android-way.html


No comments:

Post a Comment