Hi, assuming you are using WinCE there are a couple of lines you can add to the sys.txt file to make the programme close when power is turned off and resume where you left off when power is restored. Will this provide what you need?
PS: these settings might also work for some versions of android but I haven't tried.

Sent from my SM-A528B using Tapatalk