1. Are you ready for the Galaxy S20? Here is everything we know so far!

How to learn which app is running, and kill some of them?

Discussion in 'Android Development' started by Trinh Cong Minh, Apr 21, 2019.

  1. Trinh Cong Minh

    Thread Starter

    Hi, i am looking for a way to create an app which will run on the background, and when i press both volume down and volume up button it will kill all the app that currently running (some of them).

    I nailed the event click both volume button and background service but i dont know how i can kill another app thats not from my app's activity.

    I would prefer non-rooting required but if its not possible, rooting is fine since the purpose of this project is mainly education.

    Thank you for reading.

    Edit: I am not looking for a block of code, just some keywords or solutions. Sure some code example would be nice.
     



    1. Download the Forums for Android™ app!


      Download

       
  2. dontpanicbobby

    dontpanicbobby 100% That Guy
    VIP Member

    Tap on the square box on the right and close all or individual apps.
    HTH
     
    Snakeyeskm and Trinh Cong Minh like this.
  3. Trinh Cong Minh

    Thread Starter

    So what you mean is that i create something like a macro which will click on the square box and close everything?

    If thats what you mean, could you please provide me some more information on how i can simulate touch on screen please?
    I was also tried to follow that appoarch but then stuck at how to simulate touch on screen.

    Thank you for your help
     
  4. dontpanicbobby

    dontpanicbobby 100% That Guy
    VIP Member

    No. I'm not a developer, just a User.
     
  5. Trinh Cong Minh

    Thread Starter

    Oh okay, thank you anyway
     
    dontpanicbobby likes this.
  6. Trinh Cong Minh

    Thread Starter

    I checked that app out and in my opinion that app is highly overrated (No pixel reader). Anyway, this project is for education purpose which mean that i want to learn how to do it rather than get it done by using existing application.

    Thank you for your help
     
  7. Deleted User

    Deleted User Guest

    You won't be able to do that on a non-rooted device.
     
    Trinh Cong Minh likes this.
  8. Trinh Cong Minh

    Thread Starter

    So is there any solution if my device is rooted?

    I am trying to use command but it seem that it only work when my device is connected to a pc. Is that true?
     
  9. Deleted User

    Deleted User Guest

    So your first issue is to programmatically get a list of running apps on the device. Some info here

    https://stackoverflow.com/questions/3304685/how-to-get-the-list-of-running-applications

    Now how you kill an app (assuming you have permission) is another issue. If you could get process ID (PID) of the app, you could exec the kill command

    Code (Text):
    1.  
    2. int processID = // Somehow get the PID of the app
    3. Runtime runtime = Runtime.getRuntime();
    4. runtime.exec(new String[] { "/bin/bash kill " + processID});
    5.  
    P.S. This code is completely untried, it's just off the top of my head to give you some ideas.
     
    Trinh Cong Minh likes this.
  10. Trinh Cong Minh

    Thread Starter

    Say, if my device is rooted i should have permission right?

    That command that you run, does it required a pc connected to work?
     
  11. Deleted User

    Deleted User Guest

    No. kill is a standard command on Unix systems. Whether it's there on Android I can't say for sure. You'll have to do some investigation.
    What you could do is fire up an adb session to your device and see if it's there. If you can issue the kill command at the prompt, then it should work programmatically from your app too.
     
Loading...

Share This Page

Loading...