Rotation of Widget

JohnK

Active Member
Licensed User
Longtime User
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?
 

JohnK

Active Member
Licensed User
Longtime User
Upvote 0

JohnK

Active Member
Licensed User
Longtime User
This change does not appear too be working for me.

My Service module is called "WidgetService", so I added the following to my manifest file:
B4X:
'End of default text.
AddReceiverText(WidgetService,  <intent-filter>
                <action android:name="android.intent.action.CONFIGURATION_CHANGED" />
            </intent-filter>)
I then added the following to the TOP of the "Service_Start" method:
B4X:
Sub Service_Start (StartingIntent As Intent)
Log(">>ServiceStart:" & StartingIntent.Action)
...
And nothing gets logged when I rotate my phone. Where am I going wrong?
 
Upvote 0

JohnK

Active Member
Licensed User
Longtime User
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
 
Last edited:
Upvote 0

JohnK

Active Member
Licensed User
Longtime User
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.
 
Upvote 0
Top