Tasker to detect application running in background

We used to be told that tasker is only capable of detecting foreground application, if the app gets into background running, it would see it as exit.

Is it? Is there anything we can do to work this out?
Yes, there is a workaround, actually just sorts this out. It proves again how tasker can change our lives.
Okay, let us get into business.

First of all, you may launch an application, eg. QQ for Pad, which I usually play it often in my android pad.
And then, get back to the system settings, tap on the section of application, check running service, allright, you will see the icon of QQ is currently running,
tap again to get into details. Right now, you will be able to see the running process or service for the app. In this case, QQ for Pad, it’s com.tencent.android.pad:service.
Apparently it is a background service.

Stage 2, since we have got the proper running process/service name, what should we do next?
No worries. Open tasker, create a new task, in the action part, select script-run shell, command:
pgrep com.tencent.android.pad:service, use root checked, stored result in %PID.
Please note, pgrep is a linux command, which could get the process ID from the proper package name.
%PID is a user-defined variable to store PID.
Once we got the PID, we can move onto the next stage.

Stage 3, get back to the launcher desktop, open RE explorer, look into the root folder, find the folder of “proc”, tap to get into and pull down the list slowly,
you will see a folder with the name exactly the same as the PID you just got.
Okay, get into this folder, and you will find a file name: oom_adj, open it as a text file, you will see one certain digit, most likely it is 2.
Based on android default RAM control system,
if the digit stored in oom_adj is 1 or 2, it means the app is currently running in background,
if it is greater than 2, it means it is no longer running or already cached.
Well, now, you guys may probably get to know my intention on how to detect an app is running in background.

Stage 4, from this stage, we will see how to get the digit from the proper oom_adj file.
And actually we may simply just put stage 2 which we get PID from app package combined in here.
Tasker, create a task, in the action part, select script-run shell, command:
Cat /proc/$(pgrep com.tencent.android.pad:service)/oom_adj, use root, checked, stored result in %OOMADJ
If you are still confused how exactly to set up the complete profile, please be patient and follow my instruction below.

Example:
Profile:
Context: application: QQ for pad

Action 1: net-mobile data, set on --------this is to open network once qq is running in foreground which tasker application context fired.
Action 2: net-wifi-set on (Optional, depends on if necessary)
Action 3: script-run shell, command: Cat /proc/$(pgrep com.tencent.android.pad:service)/oom_adj, use root, checked, stored result in %OOMADJ
Action 4: task-if, % OOMADJ ~ 1/2
Action 5: task-wait, 20 minutes ----------------- loop in 20 minutes, so it won’t drink the battery too much.
Action 6: variable-variable clear, %OOMADJ
Action 7: task-goto, action number 3 --------------- via this action, even if QQ for Pad is running from foreground into background, the whole tasks part would still working in loop until the app has exited.
Action 8: task-else
Action 9: net-mobile data, set off --------------if QQ is no longer running or cached, just cut the network off to save data stream.
Action 10: net-wifi-set off (Optional, depends on if necessary)

NB.

if the application has registered system broadcast service, or some apps don‘t even have an exit/quit button, even if they do, tap exit, some of them would still remain background service and background process. eg. google map, google play store, etc.

Conclusion, this workaround is available for the apps which don‘t remain background service and process after exited.

时间: 2024-10-14 14:29:09

Tasker to detect application running in background的相关文章

Android NDK调试出错Unknown Application ABI, Unable to detect application ABI's的解决方案

今天在调试Android NDK的时候,ADT的控制台报了这个错误: Unknown Application ABI, Unable to detect application ABI's 在网上查了好久,终于找到了解决方案: 在工程的jni文件夹下面新建一个Makefile类型的文件,文件名为Application.(注:如果你不知道怎么新建Makefile类型的文件,可以把jni文件夹下的Android.mk文件在原地复制一份,打开之后修改里面的内容即可). 如下图: Android NDK

Unable to detect application namespace.

执行artisan命令出现以下错误: Unable to detect application namespace. composer.json格式错误.可以使用composer update执行更新,检测错误. 一般是格式错误.比如最后一个配置参数的逗号要去掉.

Android NDK调试出错Unknown Application ABI, Unable to detect application ABI's的解决方式

今天在调试Android NDK的时候,ADT的控制台报了这个错误: Unknown Application ABI, Unable to detect application ABI's 在网上查了好久.最终找到了解决方式: 在project的jni目录以下新建一个Makefile类型的文件,文件名称为Application. (注:假设你不知道怎么新建Makefile类型的文件,能够把jni目录下的Android.mk文件在原地复制一份.然后重命名为Application.打开Applica

NDK断点无法调试Unable to detect application ABI's

进行断点NDK断点调试的时候报错:   Unable to detect application ABI's 历经千辛万苦,终于可以ndk断点调试 1.ADT->Preference->Andoird->NDK 设置ndk路径 2.Application.mk设置 APP_PLATFORM := android-15(与当前工程android版本一致) APP_OPTIM := debug -DCOCOS2D_DEBUG =1 开启debug模式 3.manifest.xml修改   &

[转]iOS Tutorial – Dumping the Application Heap from Memory

?Source:https://blog.netspi.com/ios-tutorial-dumping-the-application-heap-from-memory/ An essential part of pentesting iOS applications is analyzing the runtime of the application. In this blog, I will be covering how to dump the heap from an iOS app

UWP -- Background Task 深入解析

原文:UWP -- Background Task 深入解析 1. 重点 锁屏问题 从 Windows 10 开始,用户无须再将你的应用添加到锁屏界面,即可利用后台任务,通用 Windows 应用必须在注册任何后台触发器类型之前调用 RequestAccessAsync: await BackgroundExecutionManager.RequestAccessAsync(); 资源限制 由于对于内存较低的设备的资源约束,后台任务可能具有内存限制,该限制决定了后台任务可以使用的内存上限 在内存

Microsoft .NET Pet Shop 4: Migrating an ASP.NET 1.1 Application to 2.0

249 out of 297 rated this helpful - Rate this topic Gregory LeakeMicrosoft Corporation Alan Le, Alex Arkhipov, Mike Hanley, and Steve NyholmVertigo Software, Inc. February 2006 Applies to:    Microsoft .NET Framework 2.0     Microsoft Visual Studio 2

Demystifying iOS Application Crash Logs

http://www.raywenderlich.com/23704/demystifying-ios-application-crash-logs This is a blog post by Soheil Moayedi Azarpour, an independent iOS developer. You can also find him on Google+. Have you ever had the following experience as an app developer?

Tasker to auto record incoming or outgoing call

Tasker to auto record incoming or outgoing call most of time, i was thinking of tasker can do the job like callrecorder? if yes, how to do?well, after done some homework, i have figured out the method below to share with you guys. via this method, ta