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的更多相关文章

  1. 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 ...

  2. running a background task over ssh

    原文: Why does running a background task over ssh fail if a pseudo-tty is allocated? 问题: I've recently ...

  3. laravel报错:Unable to detect application namespace.

    使用报错:Unable to detect application namespace. 是conposer.json格式不对

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

    今天在调试Android NDK的时候,ADT的控制台报了这个错误: Unknown Application ABI, Unable to detect application ABI's 在网上查了 ...

  5. 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 ...

  6. 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 ...

  7. 学习Android MediaPlayer

    Android Media Playback 原文 The Android multimedia framework includes support for playing variety of c ...

  8. Easy mistakes in c#

    ACCESS MODIFIERS c# has some access modifiers as below: public:class or member can be accessed by no ...

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

     Source:https://blog.netspi.com/ios-tutorial-dumping-the-application-heap-from-memory/ An essential ...

随机推荐

  1. 数据库-mysql管理

    MySQL 管理 启动及关闭 MySQL 服务器 首先,我们需要通过以下命令来检查MySQL服务器是否启动: ps -ef | grep mysqld 如果MySql已经启动,以上命令将输出mysql ...

  2. js权威指南---学习笔记01

    1.当函数赋值给对象的属性时,就变为了方法:2.被零整除不报错,只会返回无穷大(Infinity)或者负无穷大.例外:零除以零等于非数字(NaN).3.NaN与任何值都不相等! 4.Javascrip ...

  3. 工具类DateHandler

    package com.ctid.rachel.core.util; import java.math.BigDecimal;import java.util.Calendar;import java ...

  4. 学习shell脚本之前的基础知识

    日常的linux系统管理工作中必不可少的就是shell脚本,如果不会写shell脚本,那么你就不算一个合格的管理员.目前很多单位在招聘linux系统管理员时,shell脚本的编写是必考的项目.有的单位 ...

  5. SQL语句资料

    --语 句 功 能  --数据操作  SELECT --从数据库表中检索数据行和列  INSERT --向数据库表添加新数据行  DELETE --从数据库表中删除数据行  UPDATE --更新数据 ...

  6. Flask 对象关系

    建立一个关系 from sqlalchemy import Column, Integer, String, MetaData, ForeignKey from sqlalchemy.ext.decl ...

  7. Oracle与Sqlserver数据共享

    需求:在一个集成平台中有一个主系统使用的是Oralce数据库,子系统使用的SqlServer 数据库,如何让子系统的数据库与主系统的人员同步呢? 思路:通过服务WebService 公开接口 1.与主 ...

  8. C#基础系列 - 反射基础

    反射用于在程序运行过程中,获取类里面的信息或发现程序集并运行的一个过程.通过反射可以获得.dll和.exe后缀的程序集里面的信息.使用反射可以看到一个程序集内部的类,接口,字段,属性,方法,特性等信息 ...

  9. 30 最小的k个数

    输入n个整数,找出其最小的k个数,例如输入4,5,1,6,2,7,3,8,最小的4个数为1,2,3,4 解法一:快排思想,会改变原数组    O(n) 注意是vector<int>& ...

  10. linux 101 hacks 第一章cd命令

    本系列来源于<linux 101 hacks>,作者还写了其他101 hacks教程,读了几章,觉得技巧都还不错,很实用,做个总结收藏. cdpath 设置基目录 [ramesh@dev- ...