FORUMS
Remove All Ads from XDA

Relaunch App when it is not running in background

70 posts
Thanks Meter: 5
 
By RomainD2, Member on 24th October 2019, 10:13 AM
Post Reply Email Thread
Hi,

I have a problem with an application which should be always running in background on my android device, and sometimes, this app is shutting down.

I would like to have a tasker-task which check if this application is running, and if not, the task should relaunch the application. I have tested some stuff, but nothing is working. For example, I tried this solution : https://www.reddit.com/r/tasker/comm...he_background/ New profile > Application > choose Spotify > tick "Services" (bottom left).

But it is working only when the application is in foreground.

I found some people which use the tasker notification title trigger, because this application have a notification, but I can't find the way to set this trigger correctly, the profils never become active...

Could you give me some help to do that ?

Thanks!
24th October 2019, 03:16 PM |#2  
ktmom's Avatar
Senior Member
Thanks Meter: 2,363
 
More
Tasker can not do this directly. On a rooted device, I use a script in Termux that runs pgrep against the app in question,then calls that script via a run shell action in Tasker.

The "pgrep -x <package name>" command will not work without root permissions even if run from the command line in a terminal app.

This runs in a loop on my device checking periodically if the app is still in the background. If I were to use this perpetually, then I think I would use a time profile to check every XX minutes, which would be more battery friendly.

I use the run shell action because it's a quick way to get the PID of the app's process back to tasker without needing another profile for an intent received. The %pgrep variable contains the PID of the running app or the %pgrep is unset if the app is not running.

Termux script:
Code:
    #!/system/bin/sh

    su -c pgrep -x com.sirius
    exit 0
Tasker run shell action:
Code:
      Run Shell [
        Command:sh /data/data/com.termux/files/home/.termux/tasker/pgrep
        Timeout (Seconds):0
        Use Root: On
        Store Output In:%pgrep
        Store Errors In:%pgrepErr
        Store Result In: 
        Continue Task After Error: On
      ]
The Following User Says Thank You to ktmom For This Useful Post: [ View ] Gift ktmom Ad-Free
27th October 2019, 06:33 AM |#3  
ktmom's Avatar
Senior Member
Thanks Meter: 2,363
 
More
Actually, there a slightly easier way. It dawned on me the other day that I had never tried the command "pidof", and it turned out it's available on android.

Still requires root though.

Code:
A1: Run Shell [ 
    Command: pidof net.dinglisch.android.taskerm 
    Timeout (Seconds): 0 
     Use Root: On 
     Store Output In: %pidof 
     Store Errors In: %pidofErr 
     Store Result In: 
     Continue Task After Error: On 
 ]

A2: Wait [ 
      MS: 300 
      Seconds: 0 
      Minutes: 0 
      Hours: 0 
      Days: 0 
] 

A3: Flash [ 
      Text: PID: %pidof
      ERR: %pidofErr 
      Long: On 
]
The Following User Says Thank You to ktmom For This Useful Post: [ View ] Gift ktmom Ad-Free
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes