We used to being told that Tasker are only capable of detecting foreground application, if the app gets into background runnin G, it would see it as exit.
Is it? Is there anything we can does to work this out?
Yes, there is a workaround, actually just sorts the out. It proves again how Tasker can change our lives.
Okay, let us get to business.
First of all, 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 sections of application, check running service, allright, you'll SE E The icon of QQ is currently running,
Tap again to get into details. Right now, you'll be able to see the running process or service for the app. In this case, the 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 is 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 that 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'll see a folder with the name exactly the same as the PID you just got.
Okay, get into this folder, and you'll find a file name:Oom_adj, open it as a text file, you'll see the one certain digit, most likely it's 2.
Based on Android Default RAM control system,
If the digit stored in OOM_ADJ are 1 or 2, it means the app is currently running in background,
If it is a greater than 2, it means it is no longer running or already cached.
Well, now, your guys may probably get to know my intention on how to detect an app are running in background.
Stage 4, from this stage, we'll see how to get the digit from the proper Oom_adj file.
And actually we may simply just put stage 2 which we get the PID from the app package combined on 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 is still confused how exactly to set up the complete profiles, please be patient and follow my instruction below.
Example:
Profile:
Context:application:QQ for Pad
Action 1:net-mobile data, set on--------this was to open Network once QQ was 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, Minutes-----------------Loop in 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 are running from foreground to background, the whole tasks part W Ould still working in loops 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 had an exit/quit button, even if they Do, tap exit, some of them would still remain background service and background process. eg. Google Maps, Google Play store, etc.
Conclusion, this workaround are available for the apps which don ' t remain background service and process after exited.
Tasker to detect application running in background