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

Kill App when screen is turned off, start it when screen is turned on?

Discussion in 'Android Apps & Games' started by Wupme, Feb 9, 2016.

  1. Wupme

    Wupme Lurker
    Thread Starter


    so i was playing around with the Idea of using Spotify or something like that for Music in my Bathroom.
    I got a cheap (30 bucks) Android tablet, i know they suck, but the music apps run just fine, and thats all it has to do.

    Now i already got it set up so the screen powers on as soon as its connected to a charger, and stays on until it gets disconnected.
    If it gets disconnected, it turns the screen off after 5 Minutes.
    All done with system settings, so no apps needed here.
    It is connected to a USB Charger which is connected to the light switch of the room. And the speakers are also powered like this.

    So everything pretty much works how i want it to work.
    But there is one thing i dislike.

    Most music players i tried don't have a timeout setting, they would just keep on streaming and playing.
    And eating data and battery life in the process. Not good.

    Now i thought there should be a way to close an app (kill it) as soon as the screen is turned off.
    And it would even be more awesome, if the app is started when the screen gets turned on, but thats not really important.

    So is there any way, or app, that can kill an app as soon as the screen times out?
    Or maybe with an inactivity timer i can set.

    This is not to get any performance boosts like those snake oil apps promise. Its really just that i don't want an app to keep streaming music once the screen is turned off.

    1. Download the Forums for Android™ app!


  2. lunatic59

    lunatic59 Moderati ergo sum

    I'd probably look at Tasker for that. If it's always the music player app you wanted on, then I'm sure that can be done.
  3. Welcome to Android Forums.

    The following Tasker profiles and tasks do it. The Beeps are so you know it's executing ...
    Code (Text):
    1. Profile: Off
    2. Event: Display Off
    3. Enter: Anon
    4. A1: Beep [ Frequency:8000 Duration:1000 Amplitude:50 Stream:3 ]
    5. A2: Kill App [ App:Poweramp Use Root:Off ]
    7. Profile: On
    8. Event: Display On
    9. Enter: Anon
    10. A1: Beep [ Frequency:8000 Duration:1000 Amplitude:50 Stream:3 ]
    11. A2: Launch App [ App:Poweramp Data: Exclude From Recent Apps:Off Always Start New Copy:Off ]
    ... Thom
  4. Wupme

    Wupme Lurker
    Thread Starter

    Wow i didn't even knew something like tasker existed. And then i even get supplied with the code.
    This is awesome, thank you so much, gonna try this tomorrow :)
    El Presidente likes this.
  5. steiny180

    steiny180 Android Enthusiast

    Have a look at AutomateIt at the play $tore.

    Much simpler than ta$ker...
  6. AZgl1500

    AZgl1500 Extreme Android User

  7. Wupme

    Wupme Lurker
    Thread Starter

    Simple is not important to me, as long as it works.

    Problem i found, all of them need root access to do it.
    And i have yet to find a way to do that :(
  8. The Tasker solution I showed does not require root. I am on an un-root-ed Droid Turbo 2.

    ... Thom

    ... Thom
    lunatic59 and AZgl1500 like this.
  9. AZgl1500

    AZgl1500 Extreme Android User

    Just like Tasker, MacroDroid does not need Root to turn an app on/off.
    It is just your personal choice of whether you want an app that will do the job within 30 seconds of you installing it, or get Tasker and take a while figuring out how to program it.

    either works. and the way they handle the process is the same.

    I use the Power Charging signal to turn OFF all System Sounds period for as long as the charger is connected. My wife literally screams at me if she hears anything from my phone at all. So, the Charge Full sound just drives her up the wall.

    MacroDroid senses "charging" and the phone goes deaf....
    Taken off charge, it immediately comes back to life.

    for you, the "Action" to be taken is to "Enable/Start an app".
    that is just one macro.

    Then you create a 2nd macro and the Trigger is "Charger off",
    "Action" is close app.
    Thom likes this.
  10. Wupme

    Wupme Lurker
    Thread Starter

    It doesn't work, the tasks start, and i hear the beep, but they can't close the app.
    Neither of both apps is able to close either Spotify, Pandora or any other app on my system.

    Doesn't even work when i push the play button on the task in tasker.

    I did some research and a lot of people say i need root to do this. Or some plugin that costs additional money.

    I manged to make tasker do all kinds of nice stuff, but my main goal of the killing the app doesn't seem to work.

    Macrodroid also wasn't able to close any apps on my system.
  11. I'm not following what you are doing with Tasker.

    In Tasker there are two profiles and each has a single entry task.
    You need to have both profiles on.
    You need to exit Tasker and do a Save First if you made any changes.
    Then tap the power button to turn the screen off. You will hear the beep.
    Tap the power button again and hear the beep and the app will be displayed.

    This is killing and starting one app and in this example it is Poweramp.

    This processing will continue until the profiles are turned off (and you do an Exit Save First).

    ... Thom
  12. Wupme

    Wupme Lurker
    Thread Starter

    When editing a Task there is a button on the bottom left to start/play/execute that task

    It is not working. I understood how tasker works, i was able to make it do all kinds of stuff.
    But it can't close any apps on my system.

    Not when turning the display on and off, nor when i start the task manualy. It just doesn't work.
  13. AZgl1500

    AZgl1500 Extreme Android User

    Don't know how you tried to set up the macros in MacroDroid, but it does indeed shut down apps when I lock the screen.

    and it does indeed shut OFF all of the System sounds when the Charger is working, whether it be a wireless charge, or a usb plug in charger.

    go into Developer Options and check to see if you have something set that should not be.
  14. There are multiple paths here on the table. This is not a trivial activity. It takes some involvement. The Tasker path is being partially addressed by the OP.

    Choose which path you want to follow and tell us.

    The Tasker button you referred to is to execute a Task and not a Profile. In this one there are two Profiles that are triggering two Tasks. Both Prodiles must be On.

    If I had to guess I would guess that my sample app of Poweramp is not installed on your device and that is the reason it is not working. Chose an app that is installed on your device.

    ... Thom
  15. Wupme

    Wupme Lurker
    Thread Starter

    I actually want to use tasker since it gives me far more control.
    And i already used it to implement some other nice things, and well i also bought it and its too late to give it back lol.

    I never said the button would execute a profile, i said it would execute a task.

    The profiles are not the issue here, i got them working.

    And like mentioned, i already tried it with spotify, pandora and a few other apps. It simply doesn't close them.

    The Kill App action simply does nothing on my System.
    AZgl1500 likes this.
  16. Choose an app to launch and kill that exists on your device.
    Go to System Settings/Security/Device Administrators. Tasker must be enabled.
    Go to System Settings/Sound & Notification/Notification Access. Tasker must be enabled.
    Hitting the button on the Task should perform the launch or kill.

    ... Thom
  17. Wupme

    Wupme Lurker
    Thread Starter

    It wasn't set as device administrator, it is now.

    Its still not able to kill any apps, no matter which ones i try :(
  18. Did you reboot your device after setting Tasker as an Administrator?

    Did you launch an app using that task and can then not kill that app?

    What app are you launching and killing?

    ... Thom
  19. codesplice

    codesplice Elite Recognized Moderator

    What version of Android do you have on your tablet? Some may have stricter controls over how one application will be able to impact another.

    To be quite honest, I've never had much luck using Tasker's built-in Kill App action on a non-rooted device. There was an addition plugin that I used to make Tasker a bit more reliable with killing applications, though it's been pulled from the Play Store. It may be available from the developer's reddit post about the takedown here; I haven't verified any of the download links, though, so I can't guarantee that they're still live.
    Unforgiven, lunatic59 and Thom like this.
  20. Wupme

    Wupme Lurker
    Thread Starter

    Yes i did.

    I launched the app and can't kill it with the task.

    Spotify, i tried others, but this is the one i want to get it working with.

    Android 4.4.2
    Kernel 3.4.39

    I tried taskkill (its still available) but it asks for root rights :(
    #20 Wupme, Feb 13, 2016
    Last edited: Feb 13, 2016
  21. I am on an un-root-ed Droid Turbo 2 running 5.1.1. Launch and Kill work witout a problem.

    From what I've read elsewhere the Kill was a problem with earlier versions and the solution was to ...
    Use the Secure Settings Tasker plugin​

    From what you are experiencing it is clear that the correction was not (yet) retrofitted to support earlier versions of the system.

    To do it with Tasker on your device will need root and a plugin.

    ... Thom
  22. Wupme

    Wupme Lurker
    Thread Starter

    Yeah thats what i suspected.

    Crap, since i can't find any ways to root that stupid thing lol

    Maybe i'll do it another way, using a raspberry pi or something that kills spotify off triggered by a light sensor and give it a touchscreen or something.

    Thanks anyway, i really appreciate the help.

Share This Page