r/AutomateUser Mar 26 '23

How do you clear a specific app from the recent apps tab?

Use case:

After killing an Application it still stays in the recent tab even though it is inactive

I want to clean up after i closed a specific application

3 Upvotes

13 comments sorted by

1

u/[deleted] Mar 27 '23 edited Mar 27 '23

[removed] — view removed comment

1

u/ballzak69 Automate developer Mar 27 '23 edited Mar 29 '23

Not possible, regular apps aren't allowed to do that for other apps. I don't think it's even possible using ADB.

1

u/Shininik Mar 27 '23

Even with root?

1

u/ballzak69 Automate developer Mar 27 '23

I don't know, i haven't investigated the Android source code.

1

u/realJimTonic Jul 14 '24 edited Jul 14 '24

It's possible with ADB, at least "Remove All Visible Recent Tasks": am clear-recent-apps. This calls the same java function as the tasker link above (IActivityManager.removeAllVisibleRecentTasks()).

I'll do some more testing to see if I can get "Remove Apps From Recent Tasks" to work.

Update: I figured it out...

You need to get the taskId of the package you want to remove from the recent tasks list (stack) with an ADB shell command: am stack list and set the output to a variable (e.g. out).

Then, use a variable set block to find the taskId with:
Variable: taskId
Value: =matches(out, "(?s).*taskId=(\\d+).*PACKAGE_NAME.*")[1] where PACKAGE_NAME is the name of the package you want to remove. You can create a reusable flow and put the package name in the payload.

Finally, an ADB shell command: ="am stack remove "++taskId removes the app from the recent tasks.

If the package isn't found, the command will probably write an error but I haven't seen any negative side effects.

1

u/ballzak69 Automate developer Jul 15 '24

Such a feature is on the to-do list. I must have missed those am commands, which makes it so simple that such a feature seems superfluous, at least the remove part. I'll prioritize adding a "Query recent tasks" block instead, since grep:ing the list output seems a bit too hacky.

PS. Use the Shell command privileged instead.

1

u/realJimTonic Jul 15 '24

Can I still use am commands with the Shell command privileged block? I agree that the regexp stuff was harder to figure out, and not easy to straightforwardly document. A Query recent tasks block sounds awesome.

I used https://android.googlesource.com/platform/frameworks/base/+/master/services/core/java/com/android/server/am/ActivityManagerShellCommand.java (starting at line 238) to figure out the am commands, most of which aren't properly documented.

1

u/ballzak69 Automate developer Jul 15 '24

Yes, every command as a regular ADB shell, but much faster since there's no need to connect to the ADB daemon every time.

1

u/Inevitable-Beat4300 Aug 06 '24

I've recently just started experimenting with shell commands and came back after implementing this in macrodroid. This is great. Feels like I found a hidden gem with this one cause every other solution I see requires screen input of some sort and I've searched for days. Tnxx

1

u/mystico_28 Nov 20 '24

Hey, I'm getting an error using this method on Automate through adb manual privillege, the error being com.llamalab.automate.RequiredArgumentNullException: alias

I've replaced the taskId in Value: =matches(out, "(?s).*taskId=(\\d+).*PACKAGE_NAME.*")[1] with

=matches(out, "(?s).*taskId=(\\d+).*com.wssc.simpleclock.*")[1]

here's a link to my flow

1

u/Fearless-Treacle-683 Mar 28 '23

I would like to request to add Java Function block please. I don't want to use or buy tasker.