• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

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

Wupme

Lurker
Feb 9, 2016
9
2
Hello,

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.
 
Welcome to Android Forums.

The following Tasker profiles and tasks do it. The Beeps are so you know it's executing ...
Code:
Profile: Off
Event: Display Off
Enter: Anon
A1: Beep [ Frequency:8000 Duration:1000 Amplitude:50 Stream:3 ]
A2: Kill App [ App:Poweramp Use Root:Off ]

Profile: On
Event: Display On
Enter: Anon
A1: Beep [ Frequency:8000 Duration:1000 Amplitude:50 Stream:3 ]
A2: Launch App [ App:Poweramp Data: Exclude From Recent Apps:Off Always Start New Copy:Off ]
... Thom
 
Upvote 0
The Tasker solution I showed does not require root. I am on an un-root-ed Droid Turbo 2.
... Thom

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.
 
  • Like
Reactions: Thom
Upvote 0
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.
 
Upvote 0
Doesn't even work when i push the play button on the task in tasker.

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
 
Upvote 0
I'm not following what you are doing with Tasker.

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.
 
Upvote 0
It doesn't work, the tasks start, and i hear the beep, but they can't close the app.

Macrodroid also wasn't able to close any apps on my system.

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.
 
Upvote 0
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
 
Upvote 0
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.
 
  • Like
Reactions: AZgl1500
Upvote 0
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.
 
Upvote 0
Did you reboot your device after setting Tasker as an Administrator?
Yes i did.

Did you launch an app using that task and can then not kill that app?
I launched the app and can't kill it with the task.

What app are you launching and killing?
Spotify, i tried others, but this is the one i want to get it working with.

What version of Android do you have on your tablet?
Android 4.4.2
Kernel 3.4.39

I tried taskkill (its still available) but it asks for root rights :(
 
Last edited:
Upvote 0
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 ...
Root
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
 
Upvote 0
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.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones