'How to update appwidget after installation a new version of the application over previous version?

I have an appwidget application. After install a new version of my app over the previous one the appwidget (which was on the Home Screen) stops showing all the information - calendar events + month calendar. I see only empty widget background. I used Intent.ACTION_MY_PACKAGE_REPLACED, trying to update the appwdget in onReceive (plus necessary code in Manifest), but it didn't help... Code is below:

if (
    intent.action.equals(ACTION_AUTO_UPDATE_PERIOD) ||
    intent.action.equals(Intent.ACTION_DATE_CHANGED) ||
    intent.action.equals(Intent.ACTION_TIME_CHANGED) ||
    intent.action.equals(Intent.ACTION_TIMEZONE_CHANGED) ||
    intent.action.equals(Intent.ACTION_LOCALE_CHANGED) ||
    intent.action.equals(Intent.ACTION_PROVIDER_CHANGED) ||
        intent.action.equals(Intent.ACTION_BOOT_COMPLETED) ||
        intent.action.equals(AppWidgetManager.ACTION_APPWIDGET_UPDATE) ||
        intent.action.equals(Intent.ACTION_MY_PACKAGE_REPLACED)
    ) {
        val thisAppWidget = ComponentName(
            context.packageName, javaClass.name
        )
        val appWidgetManager = AppWidgetManager
            .getInstance(context)
        val ids = appWidgetManager.getAppWidgetIds(thisAppWidget)
        // Update widgets
        for (appWidgetId in ids) {
              updateWidgetPeriod(context, appWidgetManager, appWidgetId)
        }
    }

How to update actual appwidget after installation a new version of the application over the previous one?

Thank you in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source