I want to create an app with two widget sizes (4x2 and 4x4).
For this I created two receivers:
<receiver android:name=".widgets.CloudWidgetProviderLarge" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_large" />
</receiver>
<receiver android:name=".widgets.CloudWidgetProviderMedium" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_medium" />
</receiver>
And one configuration activity:
<activity android:name=".widgets.WidgetConfigurationActivity">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE"/>
</intent-filter>
</activity>
The two widgetProviders inherit from my abstract WidgetBaseProvider and only implement the different parts.
My problem is the following:
The onUpdate method of the concrete WidgetProvider class is called when the configuration activity is started, but not when the configuration is finished. And therefore not updating the widget when done with the configuration.
What I've tried so far in the WidgetConfigurationActivity:
This is not causing an update. Don't know what is wrong with it:
val appWidgetManager = AppWidgetManager.getInstance(this)
val views = RemoteViews(this.packageName, R.layout.widget_newscloud)
appWidgetManager.updateAppWidget(widgetData.widgetId, views)
val result = Intent().putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetData.widgetId)
setResult(Activity.RESULT_OK, result)
finish()
This works but obviously only for one widget kind:
val providerLarge = CloudWidgetProviderLarge()
providerLarge.onUpdate(this, appWidgetManager, intArrayOf(widgetId))