Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,769,355 Members 39,841 Now Online
XDA Developers Android and Mobile Development Forum

FAQ: Why You Shouldn’t Be Using a Task Killer with Android (geekfor.me)

Tip us?
 
Paul22000
Old
(Last edited by Paul22000; 19th January 2011 at 04:37 PM.)
#1  
Paul22000's Avatar
Senior Member - OP
Thanks Meter 139
Posts: 3,470
Join Date: Jan 2008

 
DONATE TO ME
Default FAQ: Why You Shouldn’t Be Using a Task Killer with Android (geekfor.me)

Here's an article posted at http://geekfor.me that is by far the best explanation I've ever seen on this issue:

Quote:
Originally Posted by flipz:
FAQ: Why You Shouldn’t Be Using a Task Killer with Android

I see this come up over and over again. People saying that a task is running in the background and they think it is killing their battery or hogging all of their memory. So their natural reaction is to download a program made to kill tasks. Here’s the thing… you are likely doing more harm than good by killing tasks that aren’t ready to end. I was the same way when I first got my CDMA Hero. There were tons of things running that I didn’t want so I just kept killing them. After a few weeks I realized that if I stopped using a task killer (and totally uninstalled it in fact) my phone actually began to run better! The applications would close themselves and things just seemed to be running better. I get that there may be short term benefits from clearing a task, but you should still take the time to read through this.

Here is some information directly from Android’s developer page. I have put the important parts in bold. This is quite a lengthy read but honestly I think it’s important. If you want the full read then you can check out the dev page here. If you just want the quick TL;DNR version then scroll to the bottom.

Quote:
Originally Posted by Google:

By default, every application runs in its own Linux process. Android starts the process when any of the application's code needs to be executed, and shuts down the process when it's no longer needed and system resources are required by other applications.

A content provider is active only while it's responding to a request from a ContentResolver. And a broadcast receiver is active only while it's responding to a broadcast message. So there's no need to explicitly shut down these components.

Activities, on the other hand, provide the user interface. They're in a long-running conversation with the user and may remain active, even when idle, as long as the conversation continues. Similarly, services may also remain running for a long time. So Android has methods to shut down activities and services in an orderly way:

  • An activity can be shut down by calling its finish() method. One activity can shut down another activity (one it started with startActivityForResult()) by calling finishActivity().

  • A service can be stopped by calling its stopSelf() method, or by calling Context.stopService().

Components might also be shut down by the system when they are no longer being used or when Android must reclaim memory for more active components.

If the user leaves a task for a long time, the system clears the task of all activities except the root activity. When the user returns to the task again, it's as the user left it, except that only the initial activity is present. The idea is that, after a time, users will likely have abandoned what they were doing before and are returning to the task to begin something new.
Quote:
Originally Posted by Google:

Activity lifecycle

An activity has essentially three states:

  • It is active or running when it is in the foreground of the screen (at the top of the activity stack for the current task). This is the activity that is the focus for the user's actions.

  • It is paused if it has lost focus but is still visible to the user. That is, another activity lies on top of it and that activity either is transparent or doesn't cover the full screen, so some of the paused activity can show through. A paused activity is completely alive (it maintains all state and member information and remains attached to the window manager), but can be killed by the system in extreme low memory situations.

  • It is stopped if it is completely obscured by another activity. It still retains all state and member information. However, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.

If an activity is paused or stopped, the system can drop it from memory either by asking it to finish (calling its finish() method), or simply killing its process. When it is displayed again to the user, it must be completely restarted and restored to its previous state.

The foreground lifetime of an activity happens between a call to onResume() until a corresponding call to onPause(). During this time, the activity is in front of all other activities on screen and is interacting with the user. An activity can frequently transition between the resumed and paused states - for example, onPause() is called when the device goes to sleep or when a new activity is started, onResume() is called when an activity result or a new intent is delivered. Therefore, the code in these two methods should be fairly lightweight.
The following diagram illustrates these loops and the paths an activity may take between states. The colored ovals are major states the activity can be in. The square rectangles represent the callback methods you can implement to perform operations when the activity transitions between states.



So… the TL;DNR Version:
  • Android is hard coded to automatically kill a task when more memory is needed.
  • Android is hard coded to automatically kill a task when it's done doing what it needs to do.
  • Android is hard coded to automatically kill a task when you haven't returned to it in a long time.
  • Most services (while possibly running in the background) use very little memory when not actively doing something.
  • A content provider is only doing something when there is a notification for it to give. Otherwise it uses very little memory.
  • Killing a process when it isn't ready only causes it to have to reload itself and start from scratch when it's needed again.
  • Because a task is likely running in the background for a reason, killing it will only cause it to re-spawn as soon as the activity that was using it looks for it again. And it will just have to start over again.
  • Killing certain processes can have undesirable side effects. Not receiving text messages, alarms not going off, and force closes just to name a few.
  • The only true way to prevent something from running at all on your phone would be to uninstall the .apk.
  • Most applications will exit themselves if you get out of it by hitting "back" until it closes rather than hitting the "home" button. But even with hitting home, Android will eventually kill it once it's been in the background for a while.

Questions? Concerns? Feel that I’m wrong? Comment below and let’s discuss!

Addendum:

One thing that I forgot to even address here is that memory works a bit differently in linux than it does in Windows. In general the way memory works is you really only need as much as you plan on using. So if your combined running programs use 100mb of memory, 150mb is more than enough. There is no need to clear what's running in memory before you hit that 150mb cap. Now in Windows it seems that the system performs a bit better when you have less stuff in memory, even if it's not full. No doubt those who have been on computers for a while will remember there used to be programs that could clear your memory in Windows also.

Linux however isn't generally affected by this. While I admit that I don't know the architecture and reason for this& linux will run the same regardless of if you have 20mb free memory or 200mb. And as I outlined above, Android will automatically start to kill applications if you do get low on memory! Stealing a quote from Chris Johnston, Buffers and cache in RAM being cleared is silly. Imagine a professor, who rather than writing all the way across the chalkboard, finishes a sentence and immediately erases and starts writing in the upper left corner AGAIN and AGAIN and AGAIN OR imagine you like a song. You record it to the beginning of a cassette tape. When you want a new song, do you re-record over the first song or record after it?"

I have also seen people incorrectly assume that the more memory in use, the faster their battery will die. This would actually be more attributed to the amount of processor cycles (CPU %) going on and not the amount of memory being taken up by a certain program. However, that does lead to a good point! When can a task manager be a good thing?? To help you determine what IS slowing down your phone; what may actually be draining your battery faster. That is actually what helped us discover that there appears to be a bug still left over from 1.5 that is causing slow downs on our CDMA Hero's even today. While an item using up memory isn't going to hurt things, an item chewing through your CPU absolutely will. Now I still don't suggest using a task killer to kill a program that is using up your processor (unless of course it is a zombie process that is going crazy, but you should probably just reboot in that case). But it can help you see what's going on with your phone.

I hope this has helped someone. With all of that said& I always encourage experimenting. It is your phone, and you can do with it what you please. If you swear that a task killer makes your phone amazing, then by all means use it! Thanks for reading.
Another great resource:

A video from Google's Android Team:

Androidology - Part 2 of 3 - Application Lifecycle
http://www.youtube.com/watch?v=ITfRuRkf2TM


And finally:

Check out the application "Task Manager". You'll notice dozens of processes running that you didn't even know were running. Here's my phone right now:



Look at the CPU usage column (the rightmost column) and notice that almost everything is at 0%. (The exception is TaskManager which is constantly polling since it's the active app. Menu -> Quit stops it.)

This is the best visualization that killing "running" apps will do nothing, since they're not really doing anything anyway. I have all these apps open yet they're all using 0% CPU. And I have "only" 47 MB free.

From monitoring this over the weeks, I've had as many as 60+ processes listed, and as few as 10. I've had as high as 200+ MB free and as low as 30 MB.

And my phone ran just the same.

Get rid of all your task killers for a week (and get WatchDog instead) and see how your phone feels.

Hope this helps clear up any confusion.
.
The Following 14 Users Say Thank You to Paul22000 For This Useful Post: [ Click to Expand ]
 
ap3604
Old
(Last edited by ap3604; 9th May 2010 at 12:24 AM.)
#2  
Senior Member
Thanks Meter 431
Posts: 1,458
Join Date: Feb 2010
Paul is always great for good information. Everyone should look over his comment's to learn new things

Got a question though, with certain apps like Music and SIPagent there's not a way to close them. I can only pause music and there's no way to exit SIPagent without using a task killer. Shouldn't I use a task killer on these two applications?
 
jblazea50
Old
#3  
Senior Member
Thanks Meter 440
Posts: 2,144
Join Date: Feb 2010
Location: Beltsville

 
DONATE TO ME
Quote:
Originally Posted by ap3604 View Post
Paul is always great for good information. Everyone should look over his comment's to learn new things

Got a question though, with certain apps like Music and SIPagent there's not a way to close them. I can only pause music and there's no way to exit SIPagent without using a task killer. Shouldn't I use a task killer on these two applications?
that's a good question; some apps doesn't have that quit button, like the Skyfire browser, so if i were to use the browser and close it, will still be running in the background? shouldn't i have to kill that app somehow?

anyway, will remove task killers now and give it a shot
 
Amrosorma
Old
(Last edited by Amrosorma; 9th May 2010 at 01:06 AM.)
#4  
Member
Thanks Meter 4
Posts: 44
Join Date: Aug 2008
Great thread as always, Paul, but which "Task Manager" are you talking about?

http://www.appbrain.com/search?q=task+manager

There are quite a few

I don't use a task manager, but I *have* used SeePU++'s task kill feature a couple times.

I think I found it:

http://www.appbrain.com/app/com.houmiak.taskmanager

And if you guys don't believe Paul:

The Following User Says Thank You to Amrosorma For This Useful Post: [ Click to Expand ]
 
Clarkster
Old
#5  
Senior Member
Thanks Meter 42
Posts: 588
Join Date: Mar 2007
Location: Sooke
Quote:
Originally Posted by jblazea50 View Post
that's a good question; some apps doesn't have that quit button, like the Skyfire browser, so if i were to use the browser and close it, will still be running in the background? shouldn't i have to kill that app somehow?

anyway, will remove task killers now and give it a shot
They all work the same way as described in the post. You don't have to quite Skyfire, the Music app, SIPagent, or anything at all. Read through the post again, the Android OS will stop those when it needs memory.

For example, if Music is playing, it asks the Android system to consider it foreground, so it will never get forced to quit. But when music is paused it just runs as a normal app. When Android needs the memory, it force quits it immediately.

Same with Skyfire, it will remain loaded in the background if no other process needs the memory. This way if you leave and go back to it quickly it will be there, and won't have to reload. When something else needs the memory Android closes Skyfire. If you force it to close all the time, you only force it to load more often when you need it again, wasting time and battery life.
The Following User Says Thank You to Clarkster For This Useful Post: [ Click to Expand ]
diversificationied Old
#6  
Guest
Thanks Meter
Posts: n/a
So how do I get more ram?
 
Amrosorma
Old
#7  
Member
Thanks Meter 4
Posts: 44
Join Date: Aug 2008
Quote:
Originally Posted by muncheese View Post
So how do I get more ram?
You don't. Applications will be closed automatically by the OS when you need more RAM.
The Following User Says Thank You to Amrosorma For This Useful Post: [ Click to Expand ]
 
jblazea50
Old
#8  
Senior Member
Thanks Meter 440
Posts: 2,144
Join Date: Feb 2010
Location: Beltsville

 
DONATE TO ME
Quote:
Originally Posted by Clarkster View Post
They all work the same way as described in the post. You don't have to quite Skyfire, the Music app, SIPagent, or anything at all. Read through the post again, the Android OS will stop those when it needs memory.

For example, if Music is playing, it asks the Android system to consider it foreground, so it will never get forced to quit. But when music is paused it just runs as a normal app. When Android needs the memory, it force quits it immediately.

Same with Skyfire, it will remain loaded in the background if no other process needs the memory. This way if you leave and go back to it quickly it will be there, and won't have to reload. When something else needs the memory Android closes Skyfire. If you force it to close all the time, you only force it to load more often when you need it again, wasting time and battery life.
thanks for the explanation; i already removed the task killers from my phone and will see how it goes
 
Paul22000
Old
#9  
Paul22000's Avatar
Senior Member - OP
Thanks Meter 139
Posts: 3,470
Join Date: Jan 2008

 
DONATE TO ME
Quote:
Originally Posted by muncheese View Post
So how do I get more ram?
You're in luck my friend!

Here you go:

http://www.downloadmoreram.com/index.html

Your phone will FLY!
The Following 2 Users Say Thank You to Paul22000 For This Useful Post: [ Click to Expand ]
diversificationied Old
#10  
Guest
Thanks Meter
Posts: n/a
Quote:
Originally Posted by Paul22000 View Post
You're in luck my friend!

Here you go:

http://www.downloadmoreram.com/index.html

Your phone will FLY!
Awesome, I left a little on the server for you guys.


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes