Detect when an app crashes with tasker and force close it and finally launch it again On my phone the app Bluetooth Share crashes randomly. With Tasker I want to be able to detect that crash, and then force close Bluetooth Share and finally launch Bluetooth Share again. (Or turn on Bluetooth again)


  PS: I already have tasker and I am rooted on CM12.1.


Any help is appreciated. Thanks!
Unfortunately, it's quite not possible. Tasker cannot detect an app crash. 

However, we can still do something about it. 

Let's first make a profile that does the killing job. It will be executed when the bluetooth goes off.


Profile (name): BTrern 


State (Context): BlueTooth Status [ Status:Off ]    (Profile triggers when BT  goes off)
Task:                                               (You can give task a name)


A1: Kill App [ App:Bluetooth Share Use Root:On ]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  (Click the + to add these actions)
A2: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (Wait for 5 seconds)
A3 (optional): [X] Launch App [ App:Bluetooth Share] &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (If you need to launch it)
A4: Bluetooth [ Set:On ]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(Turns ON blutooth)`




Note: If killing even with root is not working (there could be some problem with your Tasker or root), you can try the following shell command:

am force-stop packagename


E.g.:

am force-stop com.google.android.apps.maps


Or if that doesn't work:


pm disable
Wait  3 seconds  
pm enable


Now, the next question is how to turn off Bluetooth without executing the instructions noted above?

It's quite simple. Make another task.


Profile Status: BTrern &rarr; Off
Wait 5 seconds
Bluetooth &rarr; Off


Name this task (like BTOFF) and make a shortcut to your home screen.  

Now whenever you want to turn off your BT use this shortcut.

Let's make another task that turns on BT as well as the BTrern


Bluetooth &rarr; ON
Wait 5 sec
Profile Status &rarr; BTrern : ON


Again, use the above two task shortcuts to turn BT ON or OFF.

You can also use a scene or a widget to make it even easier once you have acquired enough knowledge with Tasker..



OLD



I do not quite understand what you mean by Bluetooth share, but I would presume you mean the activity opened by Share &rarr; Bluetooth. May be a pic or two would help.

Instead of finding a way around, first try fixing it by:


Using a Log tool like catlog. (Open catlog &rarr; set it on Error, let the crash occur and then open catlog again and save the log.)
Searching for it. You haven't provided any info about your Android model so you might have to do it yourself.


In case those doesn't work, we can use Tasker. I believe the crash will occur within few seconds of opening the activity. We can use this to our advantage.  


TRIGGER ON: (When Bluetooth Share activity opens)


If (Bluetooth Share activity close) AND (qtime &lt; 5 sec)


start (Bluetooth Share activity)

else (goto 1)`



Here, qtime is a local variable which stores for how many seconds the task is running. You can find that in Help section of Tasker.  

Also you can use Tasker Process Running (KC) for the required process.

Second Method:

Instead of that, it's much more easier to make a  Scene instead of that.


Just make a small box with one button in it which will execute the activity.  Keep it non - intrusive.
Scene1:


Kill Bluetooth Share process
Start Bluetooth Share process

TRIGGER ON: (When Bluetooth Share activity opens)  


Create Scene1


If (Bluetooth Share activity close)


wait 5 seconds
destroy scene1





With this, there will be a small overlay when you open Bluetooth Share. If it crashes you can easily execute your kill and start command. And if it doesn't crash, the scene will get automatically destroyed after 5 seconds.

May be Bluetooth File transfer can help.