Well, it's simple, make BroadcastReceiver to load at boot, and a flag somewhere like ForceClosed is set to TRUE, if the application terminated without any error, set the flag to FALSE.
When you receive a bootcast, check if ForceClosed is set to TRUE, if so, do whatever you want, and then return it to FALSE.
source share