In my system, LauncherActivity is the main screen in Homescreen and it handles the widget updates. In onStart method, AppWidgetHost.startListening is called. In onStop method, AppWidgetHost.stopListening is called.
If we switch to a widget, it switches to another application, so onStop is called for the activity, so the widget updates are stopped. Then we change some data on the application and switch back to LauncherActivity. Then onStart is called and we trigger an internal intent to finally call appWidgetManager.updateAppWidget on the widget provider. But the widget is not updated with the latest data. If we remove the widget from homescreen and add it back, then it shows the updated data.
Initially I thought the reason could be that startListening and updateAppWidget are called very quickly, so the widget provider was not still ready for updates. But even the updateAppWidget is called with 2sec delay after startListening, the widget is not updated.
The widget gets updated properly if we don’t call AppWidgetHost.stopListening in onStop. But I am using it to stop widget updates when the widget screen is not active. But even after calling startListening why the widget is not updated?