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网络编程-socket发送大数据包问题
一:什么是socket大数据包发送问题 socket服务器端或者客户端在向对方发送的数据大于对方接受的缓存时,会出现第二次接受还接到上次命令发送的结果.这就出现象第一次接受结果不全,第二次接果出现第一 ...
- python去除html空格
如下面的 <td> 柳暗花溟</td> html里面的空格 ,想直接用strip()函数去除是不可能的,必须显式的去掉\xa0 例如以上的就可以这样的方式去除空 ...
- android设备休眠
从上面的连接里面找到了一些资料: 如果一开始就对Android手机的硬件架构有一定的了解,设计出的应用程序通常不会成为待机电池杀手,而要设计出正确的通信机制与通信协议也并不困难.但如果不去了解而盲目设 ...
- springMVC源码分析--HttpMessageConverter数据转化(一)
之前的博客我们已经介绍了很多springMVC相关的模块,接下来我们介绍一下springMVC在获取参数和返回结果值方面的处理.虽然在之前的博客老田已经分别介绍了参数处理器和返回值处理器: (1)sp ...
- 安装部署Apache Hadoop (完全分布式模式并且实现NameNode HA和ResourceManager HA)
本节内容: 环境规划 配置集群各节点hosts文件 安装JDK1.7 安装依赖包ssh和rsync 各节点时间同步 安装Zookeeper集群 添加Hadoop运行用户 配置主节点登录自己和其他节点不 ...
- ssh远程执行nohup命令不退出
https://blog.csdn.net/oneinmore/article/details/50073443
- day6面向对象
面向对象介绍(http://www.cnblogs.com/alex3714/articles/5188179.htm) 世界万物,皆可分类 世界万物,皆为对象 只要是对象,就 ...
- javascript输入验证数字方法,适合充值时输入正整数验证
说明:用于验证正整数的输入,不允许输入其他字符. html: <input type="text" id="sell_jobNum" name=" ...
- vwware虚拟机无法连接外网
1.问题:动态IP时连接外网没有问题,但是将IP改为静态IP时发现没有办法连接外网 查看文件/etc/resolv.conf,里面的内容全部都被注释 [root@jenkins network-scr ...
- 接口调用 POST
/** * 接口调用 POST * @return [type] [description] */ public function portPhone(Request $request) { $pho ...