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 ...
随机推荐
- 2016-2017-2 20155309南皓芯《java程序设计》第十周学习总结
教材内容总结 网络编程 定义:网络编程就是在两个或两个以上的设备之间传输数据. 计算机网络概述: 网络编程的实质就是两个(或多个)设备(例如计算机)之间的数据传输. 网络中的每个设备都会有一个唯一的数 ...
- 判断一个字符是否为数字的两种方法(C/C++)
在平时,我们经常遇见判断字符是否为数字这种题目,虽然感觉还是很简单,不过我是个更喜欢用函数的人,因为我觉得这样更便捷,所以我更推荐第二种方式. 1.直接判断 #include <stdio.h& ...
- HTTPS、SPDY和HTTP/2的性能比较
http://www.infoq.com/cn/news/2015/02/https-spdy-http2-comparison/ https://segmentfault.com/a/1190000 ...
- Looksery Cup 2015 F - Yura and Developers 单调栈+启发式合并
F - Yura and Developers 第一次知道单调栈搞出来的区间也能启发式合并... 你把它想想成一个树的形式, 可以发现确实可以启发式合并. #include<bits/stdc+ ...
- caffe中根据 *_train_test.prototxt文件生成 *_deploy.prototxt文件 (转载)
见博客:http://blog.csdn.net/u010417185/article/details/52137825
- jump game(贪心算法)
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- 【面试总结】网易2019秋招一站式面试总结(等offer中……)
岗位:运维工程师(网易杭州) 面试时间:一天 上午十一点二十,准时开启面试,初面面试官是个看起来就像是主管的人,厚实的身体,中气浑厚的声音,整齐朴素的衬衫. 简要问题摘录如下:(后续补充答案内容) 1 ...
- CSUOJ 1895 Apache is late again
Description Apache is a student of CSU. There is a math class every Sunday morning, but he is a very ...
- 怎么将maven项目打包成war包
问题:我在eclipse上能运行,然后我想将这个maven项目打包成war然后放到另外一台机子上(其实是手动放在tomcat的webapp目录中),提供外部访问.现在问题是,一直maven项目打包一直 ...
- read()函数的困惑
#define BUF_SIZE 10 int main() { int cnt; char buf[BUF_SIZE]; cnt = read(STDIN_FILENO, buf, BUF_SIZE ...