title: Android home screen widget not updating
body: <p>I created a simple home screen widget that displays names generated from a database. I added a button to refresh the name in the TextView, but the problem is the widget does not update.</p>
  
  <p>This my Widget class:</p>
  
  <pre><code>public class QuotesWidgets extends AppWidgetProvider {
      ComponentName watchWidget;
      RemoteViews remoteViews;
      private static final String SYNC_CLICKED = "automaticWidgetSyncButtonClick";
      void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
                           int appWidgetId) {
  
          Realm mRealm;
  
          mRealm=Realm.getDefaultInstance();
          Random random = new Random();
          RealmResults&lt;names&gt; randomName = mRealm.where(Names.class).findAll();
          Names name = randomName.get(random.nextInt(randomName.size()));
          String name1 = quote.getName();
          remoteViews = new RemoteViews(context.getPackageName(), R.layout.my_widget);
          watchWidget = new ComponentName(context, MyWidget.class);
          remoteViews.setTextViewText(R.id.textview, name);
  
          remoteViews.setOnClickPendingIntent(R.id.refresh, getPendingSelfIntent(context, SYNC_CLICKED));
          appWidgetManager.updateAppWidget(watchWidget, remoteViews);
      }
  
      @Override
      public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
          // There may be multiple widgets active, so update all of them
          for (int appWidgetId : appWidgetIds) {
              updateAppWidget(context, appWidgetManager, appWidgetId);
          }
      }
  
      @Override
      public void onReceive(Context context, Intent intent) {
          super.onReceive(context, intent);
          if (SYNC_CLICKED.equals(intent.getAction())) {
              Realm mRealm;
              mRealm=Realm.getDefaultInstance();
  
              AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
              remoteViews = new RemoteViews(context.getPackageName(), R.layout.quotes_widgets);
              watchWidget = new ComponentName(context, MyWidgets.class);
              appWidgetManager.updateAppWidget(watchWidget, remoteViews);
              Random random = new Random();
              RealmResults&lt;names&gt; randomName = mRealm.where(Names.class).findAll();
              Names name = randomName.get(random.nextInt(randomName.size()));
              String name1 = quote.getName();
  
              Toast.makeText(context,name1, Toast.LENGTH_SHORT).show();
              remoteViews.setTextViewText(R.id.textview, name1);
  
  
          }
      }
      protected PendingIntent getPendingSelfIntent(Context context, String action) {
          Intent intent = new Intent(context, getClass());
          intent.setAction(action);
          return PendingIntent.getBroadcast(context, 0, intent, 0);
      }
  }
  </code></pre>
  
  <p>I used a Toast message in the example and when I click the button the Toast message appears with a different name every time so everything is working well except the change in the TextView in the widget. What is the problem?</p>