What may be happening is that since your View is attached in a BroadcastReceiver, the app itself is then "stopped" for the rest of the time and when Android decides it needs memory, stops your it outright. This may not actually be the reason, since you do have a View always showing, but since it is not part of an Activity, the system might deal with it differently.
With that said here is what I would try to do:
Subclass your preferred View class and override onDetachedFromWindow()
so it Logs/prints when the method is called. If, when this odd overlay disappearance occurs onDetachedFromWindow()
is called, then determine a way to re-add the View to the WindowManager. You can send a broadcast to be picked up by a BroadcastReceiver, or create a Listener
-like interface to dispatch the detached event. The interface would be then implemented by a long-running part of your app (a Service).
You could also see if the OrientationEvenListener
does anything interesting when the overlay disappears.
If all else fails, you could re-add the View periodically. Not the most optimal solution, but it does ensure that the overlay reappears.
The above approaches could also be implemented in a long-running foreground service, to ensure that Android gives priority to your App and won't be so quick to kill it.