Tasker as an Automated Task Manager

The debate about whether or not to use an automatic task killer in Android is for another day. The general consensus seems to be don’t, but regardless, we all have them in case of troublesome processes (even if you can long-press the back button) and therefore I’ve produced this tutorial to show you how to use Tasker to create one that you can configure how you wish, should you wish!

If nothing else, I hope there’s a few good Tasker tips in here, that I’m sure will come in handy for your other profiles.

Preparation

For best practice, testing and understanding, you’ll need:

1) A Terminal Emulator
2) A Task Killer (!)
3) The Locale Execute Plug-in for Tasker (make sure this is installed prior to importing the profile)
4) A speech engine – Pico TTS for example.

The Short Winded Tutorial_

It kills sh*t loads of processes.

Proceed to the download!

The Long Winded Tutorial

Import the profile and ‘un-tick’ it to make sure it is not active until you have edited it to suit your needs.

The trigger for this profile is time based and set up as standard to run every 30 minutes between the times you are likely to be using your phone. Be sure that the activation time does not match that of your AutoSync Profile that you may/should/could be using from here, or otherwise how often your standard email and widgets sync with their individual settings – you don’t want those processes being killed mid-sync.

In this profile, Tasker will use Linux commands via the Locale Execute Plug-in to kill processes you have specified. Let’s get familiar with them.

Open up the Terminal Emulator and type:

su

then:

ps

The current running processes will be listed. You’ll note that all applications you would want to kill are assigned a process ID (PID) and an application number app_XX (listed under 'User'). The application process (process name) is listed at the end, such as com.android.google.browser.

A process can be killed using its corresponding PID. Try it with an application you see in the list (NOT A SYSTEM PROCESS!):

pkill 3456

Unfortunately, the PID changes and therefore is not a constant we can use to terminate applications. We therefore have to focus on the process name – bbc.iplayer.android for example.

Try killing an application by name (open it first, list the processes again to make sure it’s there and then see if it has gone afterwards by listing processes again):

pkill com.google.android.youtube

Sometimes a process is persistent and needs further encouragement (execution) to die:

pkill -9 com.facebook.katana

Sometimes a process refuses to die – this can be because there are other processes associated with it that are not killed by the above.

Killall -9 com.levelup.beautifulwidgets

Then you have some pesky processes/services that just restart themselves back up immediately after killing them. I've had this problem with the newest version of slacker radio. Another option is to disable the application all together with the commands below. I find that if I disable the process and then re-enable it will not restart until I launch the application manually like I want it.

pm disable com.slacker.radio

The issue is that you can no longer use the application after you have disabled it unless you explicitly re-enable it with this command:

pm enable com.slacker.radio

I've found that the pm disable and enable commands are a little fussy when requesting super user permissions. I would test a task for disable, and quickly go back to your home screen to wait for the prompt for super user permissions. Then repeat the process for the enable command prior to using them in any automated tasks.

That’s the process killing commands lesson complete and only leaves us with one small issue = What if you are using the process at the time? Obviously we don’t want the browser killed if you are in the middle of surfing, so we have to use a variable to make certain of this.

The chosen built in variable is %LAPP, which is the last foreground application used. By making sure this isn’t killed, it’ll stop your current program being terminated in the middle of a message to someone! Therefore, each separate action to kill a process has an IF statement included to prevent the termination if that application is currently being used.

There are plenty of examples in the profile for you to use, but of course you’ll want to add your own entries in the KillProcesses task by:

+
Plugin
Execute
Edit
And then type (or even better paste):
@! pkill -9 and then the process name* (@! Stops the commands appearing on the screen)
Press the back button to save
Click IF
%LAPP
Click ‘~’ select ‘doesn’t match’
Enter the application nameXX.
Done

  • The process name can be found and noted in the Terminal Emulator. Alternatively, often the process names are listed in the Task Manager you are already using.
  • In the profile, there is a speech task, popup notification and a STOP task, these are there to discover the correct application name. Open the application you want to add to the list, long hold the home button and select Tasker and then press ‘test’. Tasker will say the name of the application and show how it is spelt on the screen. If the speech says ‘Launcher’, you may need to navigate back to Tasker (after opening the desired app) via the notification bar.

Copying all of the process names and completing the IF statements can be a little tedious, but when it’s done, it’s done… Test each new action to ensure the application is actually killed – just drag it above the STOP action. The Super User application may request permission first time (for each application command). Go to your current Task Manager, refresh it and check the application was terminated! If it wasn’t, try the ‘killall -9’ command detailed above. I have to use this for Beautiful Widgets and Titanium Backup as they are stubborn (and return again soon).

When you've completed your list, delete the pop-up, speech and stop actions and you're good to go.

Finally, it couldn’t be easier to create a widget for the home-screen to activate KillProcesses whenever you like. Hold down somewhere on the home-screen, select widgets. Select Tasker. Select Task. Select KillProcesses. Select your icon and hit ‘make widget’! Done!

There you have it! Your very own self created task murderer at the touch of a button!

Enjoy!

Shortfalls

You are unable to kill a troublesome process if it’s not in your task list!

Download here

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License