Task Killer written in Python

Discussion in 'Android Hacks and Help' started by brianhellno, Aug 24, 2010.

DroidForums.net is the premier Android Forum - Registered Users do not see these ads. Please Register - It's Free!
  1. brianhellno
    Offline

    brianhellno New Member

    Joined:
    Jun 13, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Ratings:
    +0
    Just wanted to get some feedback for a task killer I wrote for android in Python. I used the SL4A .apk which you can get from here:

    android-scripting - Project Hosting on Google Code

    Then I installed the Python module which that page will also help you out with.

    If you give it a try let me know if it worked and what you think of it. I'm also interested if anyone has any suggestions to make it better script wise or just in general. To use this script create a new Python script and paste this script into the coding area. On to the code:

    Code:
    import android
    
    droid = android.Android()
    
    a = droid.getRunningPackages()
    
    proclist = a[1]
    
    def taskkiller(proclist): 
       title = 'Running Processes'
       droid.dialogCreateAlert(title)
       droid.dialogSetNeutralButtonText('Kill Process')
       droid.dialogSetMultiChoiceItems(proclist, None)
       droid.dialogShow()
       droid.dialogGetResponse()
       choice = droid.dialogGetSelectedItems().result
       return choice
    
    x = taskkiller(proclist)
    
    for y in x:
       droid.forceStopPackage(proclist[y])
       print '%s was closed' % proclist[y]
    
    Basically the script gathers all of the currently running processes and creates an alert dialogue. In the dialogue you can select all of the processes that you want to close and the script kills them. Its very simplistic but I like it. To be completely honest I have no coding experience and I pretty much wrote this with trial and error and a lot of reading about Android and Python. Learned a lot in the process though. I'm thinking my next script will be an .apk uninstaller and re-installer. Anyways enjoy.
  2. aminaked
    Offline

    aminaked Silver Member

    Joined:
    Jan 10, 2010
    Messages:
    2,186
    Likes Received:
    0
    Trophy Points:
    101
    Location:
    California, USA
    Ratings:
    +0
  3. Abe21599
    Offline

    Abe21599 DF Super Moderator Rescue Squad

    Joined:
    Dec 22, 2009
    Messages:
    6,345
    Likes Received:
    30
    Trophy Points:
    163
    Location:
    Ohio
    Ratings:
    +30
  4. brianhellno
    Offline

    brianhellno New Member

    Joined:
    Jun 13, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Ratings:
    +0
  5. Abe21599
    Offline

    Abe21599 DF Super Moderator Rescue Squad

    Joined:
    Dec 22, 2009
    Messages:
    6,345
    Likes Received:
    30
    Trophy Points:
    163
    Location:
    Ohio
    Ratings:
    +30
    well as long as you understand how android works, do what works for you.

    but just so you know, you can do both of those in settings.

    im not knocking your work, i cant do it, but its already incorporated in android
  6. brianhellno
    Offline

    brianhellno New Member

    Joined:
    Jun 13, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Ratings:
    +0
  7. aminaked
    Offline

    aminaked Silver Member

    Joined:
    Jan 10, 2010
    Messages:
    2,186
    Likes Received:
    0
    Trophy Points:
    101
    Location:
    California, USA
    Ratings:
    +0
  8. Abe21599
    Offline

    Abe21599 DF Super Moderator Rescue Squad

    Joined:
    Dec 22, 2009
    Messages:
    6,345
    Likes Received:
    30
    Trophy Points:
    163
    Location:
    Ohio
    Ratings:
    +30
    yes please no discouragement meant here - keep it up :)
  9. brianhellno
    Offline

    brianhellno New Member

    Joined:
    Jun 13, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Ratings:
    +0
    Its cool I appreciate that you were up front with me. I mainly wrote the task killer to see if I could do it and thought I'd share in case anyone else was interested and to hopefully get feedback on the code. I'm thinkin my next script will be more useful. I just need to learn how to access the file system from python.
  10. brianhellno
    Offline

    brianhellno New Member

    Joined:
    Jun 13, 2010
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Ratings:
    +0
    Lol thanks for the encouragement. When I'm done with my next script I'll be sure to post it here.
Search tags for this page

android apps written in python

,

dialogsetmultichoiceitems

,
droid adb force-kill
,
getrunningpackages sl4a
,
python kill process priv
,
python killer app
,
python taskkill
,

sl4a kill process

,

sl4a play mp3

,
sl4a python kill app