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.
Tasker to detect application running in background的更多相关文章
- HOW TO REMOTELY DEBUG APPLICATION RUNNING ON TOMCAT FROM WITHIN INTELLIJ IDEA
This post would look into how to tackle and debug issues in scenarios where they only occur in produ ...
- running a background task over ssh
原文: Why does running a background task over ssh fail if a pseudo-tty is allocated? 问题: I've recently ...
- laravel报错:Unable to detect application namespace.
使用报错:Unable to detect application namespace. 是conposer.json格式不对
- Android NDK调试出错Unknown Application ABI, Unable to detect application ABI's的解决方式
今天在调试Android NDK的时候,ADT的控制台报了这个错误: Unknown Application ABI, Unable to detect application ABI's 在网上查了 ...
- Tasker to detect and vibrate once the ougoing call is being answered
I happen to find that for GSM standard phone, call duration would be created into sql database only ...
- Why is an 'Any CPU' application running as x86 on a x64 machine?
It's likely that you linked some assemblies that are not Any CPU, but include native code (or are ...
- 学习Android MediaPlayer
Android Media Playback 原文 The Android multimedia framework includes support for playing variety of c ...
- Easy mistakes in c#
ACCESS MODIFIERS c# has some access modifiers as below: public:class or member can be accessed by no ...
- [转]iOS Tutorial – Dumping the Application Heap from Memory
Source:https://blog.netspi.com/ios-tutorial-dumping-the-application-heap-from-memory/ An essential ...
随机推荐
- python dict交换key value值
方法一: 使用dict.items()方式 dict_ori = {'A':1, 'B':2, 'C':3} dict_new = {value:key for key,value in dict_o ...
- 打开mvc项目无法运行,报"Unable to launch the IIS Express Web server"
今天遇到一个问题,打开asp.net mvc 项目,右击浏览器运行,无法运行... 提示下面错误, 解决方案: 删除项目文件夹下的 .vs 文件夹,然后重新打开项目运行即可 参考:http://www ...
- Filter过滤器-JavaWeb三大组件之一
Servlet.Filter.Listener是JavaWeb的三大组件,给Web开发提供了很大的便利. 什么是Filter? Filter,过滤器.类似与生活中的净水器.空气净化器. JavaWeb ...
- 在EC2上创建root用户,并使用root用户登录
今天开始研究亚马逊的云主机EC2,遇到了一个问题,我需要在EC2上安装tomcat,但是yum命令只能是root用户才可以运行,而EC2默认是以ec2-user用户登录的,所以需要切换到root用户登 ...
- jquery中获取iframe的id的方法:
jquery中获取iframe的id的方法: var frameId = window.frameElement && window.frameElement.id || ''; al ...
- sql server2014 企业版 百度云下载
sql server2014 企业版 百度云下载 链接: https://pan.baidu.com/s/1j7a6RWwpvSzG-sF7Dnexfw 提取码: 关注公众号[GitHubCN]回复获 ...
- Hive(六)内置函数与高级操作
一内置函数 1 数学函数 Return Type Name (Signature) Description DOUBLE round(DOUBLE a) Returns the rounded BIG ...
- 团体队列(UVa540)
题目具体描述见:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_prob ...
- 【LOJ】 #2025. 「JLOI / SHOI2016」方
题解 有什么LNOI啊,最后都是JLOI罢了 一道非常--懵逼的统计题 当然是容斥,所有的方案 - 至少有一个点坏掉的正方形 + 至少有两个点坏掉的正方形 - 至少有三个点坏掉的正方形 + 至少有四个 ...
- MySQL 相关知识细节及解析
1,删除表中所有记录使用delete from 表名:还是用truncate table 表名 删除方式:delete 一条一条删除,不清空auto_increment记录数 truncate 直接将 ...