private static void initFlavorContact(Context context, int appWidgetId) {
   try {
     Integer selectedGroupId =
         Integer.parseInt(
             String.valueOf(
                 FlavorContactsConfigureActivity.loadPref(
                     context, appWidgetId, FlavorContactEnums.GROUP_ID)));
     flavorContact = new FlavorContact(context, selectedGroupId);
     flavorContact.loadContacts(context);
   } catch (Exception ex) {
     flavorContact = new FlavorContact(context, -1);
   }
 }
  public static RemoteViews updateWidgetListView(Context context, int appWidgetId) {

    // which layout to show on widget
    RemoteViews remoteViews =
        new RemoteViews(context.getPackageName(), R.layout.flavor_contact_widget);

    // RemoteViews Service needed to provide adapter for ListView
    Intent svcIntent = new Intent(context, FlavorContactRemoteViewsService.class);
    svcIntent.putExtra(FlavorContactEnums.GROUP_ID, flavorContact.getGroupId());
    svcIntent.putExtra(FlavorContactEnums.CONTACTS, Utilities.getGson(flavorContact.getContacts()));
    // passing app widget id to that RemoteViews Service
    svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    // setting a unique Uri to the intent
    // don't know its purpose to me right now
    svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));
    // setting adapter to listview of the widget
    remoteViews.setRemoteAdapter(appWidgetId, R.id.gridView, svcIntent);
    // setting an empty view in case of no data
    remoteViews.setEmptyView(R.id.empty_view, R.id.empty_view);

    // This section makes it possible for items to have individualized behavior.
    // It does this by setting up a pending intent template. Individuals items of a collection
    // cannot set up their own pending intents. Instead, the collection as a whole sets
    // up a pending intent template, and the individual items set a fillInIntent
    // to create unique behavior on an item-by-item basis.
    Intent toastIntent = new Intent(context, FlavorContactsWidget.class);
    // Set the action for the intent.
    // When the user touches a particular view, it will have the effect of
    // broadcasting TOAST_ACTION.
    toastIntent.setAction(FlavorContactsWidget.ACTION_TOAST);
    toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));
    PendingIntent toastPendingIntent =
        PendingIntent.getBroadcast(context, 0, toastIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setPendingIntentTemplate(R.id.gridView, toastPendingIntent);
    return remoteViews;
  }