I'm working with a chinese tablet which needs to be initialized every time after it's connected to a power source.

I'm using Tasker to do so. Problem is: this condition makes tasker execute the reboot command over and over, and it becomes a bootloop.

What should I do in order to initialize the tablet when a power source is attached, but avoid it from entering the bootloop?

Edit: TaskerProfile

<TaskerData sr="" dvi="1" tv="4.6u3">
<Profile sr="prof2" ve="2">
<State sr="con0" ve="2">
<Int sr="arg0" val="1"/>
<Profile sr="prof5" ve="2">
<State sr="con0" ve="2">
<Int sr="arg0" val="1"/>
<Project sr="proj0" ve="2">
<Img sr="icon" ve="2">
<Task sr="task4">
<Action sr="act0" ve="7">
<Str sr="arg0" ve="3">Documents/sdcard.txt</Str>
<Str sr="arg1" ve="3">0</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
<Task sr="task6">
<Action sr="act0" ve="7">
<Str sr="arg0" ve="3">Documents/sdcard.txt</Str>
<Str sr="arg1" ve="3">%True</Str>
<Action sr="act1" ve="7">
<Str sr="arg0" ve="3">Documents/sdcard.txt</Str>
<Str sr="arg1" ve="3">1</Str>
<Int sr="arg2" val="0"/>
<Int sr="arg3" val="0"/>
<ConditionList sr="if">
<Condition sr="c0" ve="3">
<Task sr="task7">
<Action sr="act0" ve="7">
<Str sr="arg0" ve="3">reboot</Str>
<Int sr="arg1" val="0"/>
<Int sr="arg2" val="1"/>
<Str sr="arg3" ve="3"/>
<Str sr="arg4" ve="3"/>
<Str sr="arg5" ve="3"/>
<ConditionList sr="if">
<Condition sr="c0" ve="3">

1 Answer 1


If I understood the question correctly, you want to connect the device to a power source which triggers Tasker to reboot the device (for initialization). But when the device reboots itself Tasker finds that the power source is connected so it repeats the task again. Your goal is to make Tasker reboot only once while power source remains connected. If the source is to be removed and re-inserted again, then Tasker should do the reboot again only for once.

Based on this understanding, I proposed the following solution:

The solution is very trivial. I'm using two profiles in Tasker, namely:

  1. Not power USB
  2. Power USB

These two profiles, as obvious, will be triggered by connecting/disconnecting the power source to the Android device. I'm using a file's content as a condition here to restrict boot-loop.

Note: For this answer, I chose my power source as USB only.


Regarding the file content:

  1. Create an empty file in your default storage. (I created a file named sdcard.txt in /sdcard. The location of this file is /sdcard/sdcard.txt.)
  2. Open this file in a text editor in Android and add 0 in it. (I used 920 Text Editor).
  3. Note that there is no logical reasoning in using 0 only. It will be used in a conditional statement only. You're at liberty to try an another number.

Regarding Profiles and Tasks in Tasker app:

  1. Launch Tasker.
  2. Under Profiles tab create a Profile by tapping +State → Power → Power.
  3. Under Source choose USB.
  4. Check Invert -- this will make Not power USB profile.
  5. Press Back key/button once and select New Task.
  6. Add a name for your task (persistent) or leave it blank (deleting profile will delete it as well).
  7. Under Tasks tab tap +FileWrite File.
  8. Under File field mention the location of your text file. In this case, it is /sdcard/sdcard.txt.
  9. Write 0 under Text field.
  10. Uncheck Append and Add Newline. -- we want to replace the content, so no appending should be done.
  11. Tap Back key/button twice to save this task.
  12. In order to create Power USB profile, repeat step 2,3,5 and 6, respectively.
  13. Under Tasks tab tap +FileRead File.
  14. Repeat step 8.
  15. Under To Var type %True -- You can change %True to any other name. Make sure that you capitalize at least one letter of your variable to make it non-local. See this to know more.
  16. Repeat step 11, 7 and 8.
  17. Type 1 under Text field.
  18. Repeat step 10.
  19. Tap + corresponding to If. Add %True and 0 in fields respectively. It should look like %True ~ 0.
  20. Repeat step 11.
  21. Under Tasks tab tap +CodeRun Shell.
  22. Type reboot under Command. (My device is rooted, so I provided root permissions to this step to avoid any hassle.) As a soft-reboot option, you can use killall zygote instead of reboot.
  23. Check Use Root if your device is rooted.
  24. Leave Store Output In and Store Errors In blank.
  25. Repeat step 19 and 20.
  26. Go to Profiles and enable both profiles. To save yourself from unnecessary trouble, disable any other power related profile other than the ones mentioned above.
  27. Tasker must be Enabled. You can check this by tapping Menu key/button once and amongst the options, Disable tasker would be visible. Also, if this app is running and you happen to minimize it, then as a default setting you would see its icon in the Status bar with the profile mentioned there (if activated).

We're good to go.

  • Go to Home Screen of your device.
  • Connect power source (we used USB only here).
  • Your device will reboot. Do not disconnect power source to verify that boot-loop vanished.
  • When the device comes back to Home Screen after reboot, you can see that Power USB profile is activated in tasker yet there is no boot-loop, not to mention that your initialization is also done. :)
  • Disconnect power source and the profile will switch to No power USB.
  • Connect power source again and device will reboot again for once.

Status: Objective Completed. Done!

  • It is switching between both profiles, but it doesn't execute the RunShell "reboot" task
    – Machado
    Commented May 11, 2015 at 19:15
  • @Tardo I traced this issue. If I uncheck root option in this task, then the device doesn't reboot at all. Guess what, no error in logs of Tasker as well. I checked root option and it worked fine. I'm having this feeling that your device is un-rooted.
    – Firelord
    Commented May 11, 2015 at 19:22
  • I'm using SuperSU from Chainfire to root the device
    – Machado
    Commented May 11, 2015 at 19:23
  • If I execute (manually) the reboot task, it will reboot
    – Machado
    Commented May 11, 2015 at 19:24
  • Can you send me the screen shots of all the profiles and tasks that you made using this answer in details? IDK how to export and restore tasker data.
    – Firelord
    Commented May 11, 2015 at 19:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .