I tried searching, but I could not find it. Sorry, it seems like such an obvious question that must of been answered many times.
Within a widget, how do I trap the event of the screen being rotated? When on a device, the images I have loaded all disappear, so I clearly need to perform a redraw. But what events within B4A will be called in this situation?
I did a little more digging to see how it is handled in pure Java, and found the resolution using the BroadcastReceiver library. Thanks Thomas. :sign0188:
This library will only listen for intents while the service is alive. Assuming that you do not call Service.StartForeground then eventually the service will be killed.
You can use the manifest editor to add an intent filter. This way the service will be created for you if it is not already running.
My problem is that you were also right in that the service does not last if its is not visible. So If I swipe to a different homescreen, and rotate my phone, and then swipe back, it has not redrawn :sign0080:
PS: That was the original page I read that gave me the hint of using BroadcastReceiver's
This library will only listen for intents while the service is alive. Assuming that you do not call Service.StartForeground then eventually the service will be killed.
I had a quick play / test at starting my widget service with "Service.StartForeground". It now appears to receive the intent, however, drawing the widget while it is off screen, under these circumstances does not appear to "stick" when I scroll back to the screen with the widget. However, under the circumstance where the widget is visible, it all works. I have tested with logging that the drawing routines are being called under both circumstances, and they are. But if they are started by my normal timed service start, it works as expected; on the intent, I issue a service start with StartServiceAt("", DateTime.Now, False) after setting some variables to indicate a redraw is required. I'm confused as to how it can behave differently, almost as if it knows how to $@#& me off.