Force a running app into the background?

436 views
Skip to first unread message

Soudane GMTA

unread,
Nov 25, 2021, 10:59:51 PM11/25/21
to Tasker
I'm running the latest Tasker beta under Android 10.

I'm looking for a way for Tasker to force a running app into the background. I know that there is a "Kill App" action, but I don't want the app to die. I just want it to no longer have the screen focus. This is equivalent to pressing the "Back" button for most apps, although some apps capture that button press and don't immediately lose their screen focus.

If possible, I'd like a way to force any app that is currently in the foreground to go into the background.

Is there a way to do this in Tasker?

Thank you in advance.



Soudane GMTA

unread,
Nov 25, 2021, 11:06:10 PM11/25/21
to Tasker
Oh! I figured it out!

AutoInput plugin=>Global Action=>Back

Soudane GMTA

unread,
Nov 27, 2021, 3:45:17 PM11/27/21
to Tasker
On Thursday, November 25, 2021 at 11:06:10 PM UTC-5 Soudane GMTA wrote:
Oh! I figured it out!

AutoInput plugin=>Global Action=>Back

... except for the fact, as I mentioned, that some apps trap the "Back" button and don't immediately go into the background.

Is there a non-Back-button way that Tasker can put an app into the background?

João Dias

unread,
Nov 29, 2021, 4:26:15 AM11/29/21
to tas...@googlegroups.com
Use the Go Home action instead.

Thank you for your contact.

   Join: connect multiple devices (send pushes, remote SMS, notifications) on Android, Windows, Mac, Linux
   Tasker: customize/automate anything on your phone!
   AutoApps: add advanced functionality to Tasker via plugins

     

João Dias

Soudane GMTA

unread,
Nov 29, 2021, 5:57:46 AM11/29/21
to Tasker
Thank you very much. However, I don't necessarily want to end up with the Home screen showing after putting the app in the background.

I wasn't clear about stating what I want to do. The following scenario explains in more detail ...

1. App-A is running in the foreground.
2. Due to a Tasker context, Tasker launches App-B. It is now running in the foreground.
3. Tasker performs some tasks.
4, Tasker somehow sends App-B into the background.
5. App-A (not the Home screen) is now running in the foreground again.

I'm looking for a way to perform Step 4 so that Step 5 is realized.

Robert Ryan

unread,
Nov 29, 2021, 7:25:23 AM11/29/21
to tas...@googlegroups.com, Soudane GMTA
You could try the Load Last App action. That would launch App-A back to the foreground. 
--
You received this message because you are subscribed to the Google Groups "Tasker" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tasker+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tasker/9fc15a32-fff9-4cc4-ac95-e2a012fab446n%40googlegroups.com.

Soudane GMTA

unread,
Nov 29, 2021, 1:20:30 PM11/29/21
to Tasker
Thank you very much. However, if I use Load Last App in my Step 4, then App-B remains in the foreground, because after App-B has been launched in Step 2, it then becomes the "last app".

However, I figured out a different solution. First of all, I'm now using the following profile and task that you recently suggested in a different thread:

    Profile: Track App
    Settings: Restore: no
     Event: App Changed [ Output Variables:* Package:* ]
    
    Enter Task: Anon
    
    A1: Variable Set [
         Name: %AppName
         To: %app_name
         Max Rounding Digits: 3 ]

This profile and task ensure that the %AppName variable always contains the name of the app which is currently in the foreground. I then write a task (which I'll call TemporarilyLaunch), which does the following:

(A) Set the local variable %currapp to %AppName.
(B) Launch App-B
(C) Tasker does a few things
(D) Launch %currapp

Then, my scenario becomes this ...

1. App-A is running in the foreground.
2. Due to a Tasker context getting triggered, Tasker invokes TemporarilyLaunch

After Step 2 completes, App-A is in the foreground again.

This can be generalized so that TemporarilyLaunch takes two parameters: the name of the app to be temporarily launched and the name of another task. In this case, TemporarilyLaunch would do the following:

(A) Set the local variable %currapp to %AppName
(B) Launch app %par1
(C) Synchronously perform task %par2
(D) Launch app %currapp


aa6vh

unread,
Nov 30, 2021, 10:27:31 AM11/30/21
to Tasker
I do this all the time on my tablets running my home automation. Launching a weather radar program for example, then returning to the home automation screen.

I have found that some apps require multiple "back button presses" to actually go away. So I put a loop into my Tasker Task, which will do the Autoinput global back, check to see if the app has exited, and if not, do it again (for a maximum of 10 times).

Soudane GMTA

unread,
Nov 30, 2021, 7:41:03 PM11/30/21
to Tasker
I was in the process of coding up something like that, as well, but then I thought of the procedure that I outlined in the message in this thread that is prior to yours.  It doesn't need button-click management at all, and at least for the way I use my device, it's cleaner and more straightforward.

But your method is also functional and workable in many cases, and I'm not trying to criticize it.
Reply all
Reply to author
Forward
0 new messages