I'm creating a world_clock widget which I can place on my desktop. For the widget I can select which timezone I would like to use. Only problem I'm now having is that when I select a timezone, store this in the shared preferences and send broadcast to update the clock, all my instances of the widget get updated.
The problem here seems to be that all my widget instances have the same widget Id. I retrieve the ids with below code.
val thisWidget = ComponentName(context, WorldClockWidget::class.java)
val manager = AppWidgetManager.getInstance(context)
val appWidgetIds = AppWidgetManager.getInstance(context).getAppWidgetIds(thisWidget)
I also thought of storing the data in the shared preferences using the position of the widget. But the problem is I can't get the position of the widget without clicking it. (After clicking it you can get the position using sourceBounds, but I haven't found a way to do this without this.
Is there a way to store the data for the widgets separately. Or is there a way to get the position of the widget without clicking it?
Kind regards,
JKorsten