Skip to content
Permalink
Browse files

[Widget] Remove instantiation of RemoteViews from updateAppWidget() m…

…ethod and instead create in both onUpdate() and onReceive() methods to avoid NullPointerExceptions.
  • Loading branch information...
thecosmicfrog committed May 14, 2019
1 parent f0c54f7 commit 28c1b12c4d80a452c184b76c9e256ced1dfb70f5
@@ -100,6 +100,9 @@

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
/* Construct a RemoteViews object. */
remoteViews = new RemoteViews(context.getPackageName(), R.layout.stop_forecast_widget);

/* There may be multiple widgets active, so update all of them. */
for (int appWidgetId : appWidgetIds) {
Log.i(LOG_TAG, "Widget updating with ID: " + appWidgetId);
@@ -135,6 +138,9 @@ public void onReceive(@NonNull Context context, @NonNull Intent intent) {
ComponentName thisWidget = new ComponentName(context, StopForecastWidget.class);
int[] appWidgetsIds = appWidgetManager.getAppWidgetIds(thisWidget);

/* Construct a RemoteViews object. */
remoteViews = new RemoteViews(context.getPackageName(), R.layout.stop_forecast_widget);

int indexNextStopToLoad = Preferences.indexNextStopToLoad(context);
List listSelectedStops = loadListSelectedStops(context);

@@ -354,9 +360,6 @@ private static void startWidgetListenerService(@NonNull Context context, int[] a
*/
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId) {
/* Construct the RemoteViews object. */
remoteViews = new RemoteViews(context.getPackageName(), R.layout.stop_forecast_widget);

/*
* Set up Intents to register taps on the widget.
*/

0 comments on commit 28c1b12

Please sign in to comment.
You can’t perform that action at this time.