title: Updating widget after changing preferences
body: <p>Before I begin, I want to note that I have looked through other questions including <a href="https://stackoverflow.com/questions/3119628/using-preferencesactivity-from-a-widget">this one</a>. I cannot get anything to work right now.</p>
  
  <p>I am trying to set up my widget's preferences; in this case, I have a checkbox preference to either display a percentage or not. In my WidgetConfig class, I have the checkbox preference set up and am trying to use the onBackPressed method to make the widget update.</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      addPreferencesFromResource(R.xml.new_widget_config);
  
      final CheckBoxPreference checkBoxPref = (CheckBoxPreference) getPreferenceManager().findPreference("checkboxPref");
      checkBoxPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
          public boolean onPreferenceChange(Preference preference, Object newValue) {
  
              SharedPreferences myPreferences = context.getSharedPreferences(PREFS_NAME, 0);
              SharedPreferences.Editor prefEditor = myPreferences.edit();
  
              if (newValue.toString().equals("true"))
              {
                  prefEditor.putBoolean("checkboxPref", true);
                  prefEditor.commit();
              }
              else
              {
                  prefEditor.putBoolean("checkboxPref", false);
                  prefEditor.commit();
              }
              return true;
          }
      });
  }
  
  @Override
  public void onBackPressed() {
      Intent intent=getIntent();
      Bundle extras=intent.getExtras();   
      int widgetId=extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
  
      // this is the intent broadcast/returned to the widget
      Intent updateIntent = new Intent(this, BatteryInfoData.class);
      updateIntent.setAction("PreferencesUpdated");
      updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
      sendBroadcast(updateIntent);
  }
  </code></pre>
  
  <p>When I try and put the following code into my onReceive method, I get errors that the action cannot be resolved to a variable. Am I doing this right?</p>
  
  <pre><code>    @Override
  public void onReceive(Context context, Intent intent) {
      if ("PreferencesUpdated".equals(action)) {
          RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.widget);
          int appWidgetId = intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
          updateWidgetView(context, remoteView, appWidgetId);
      }   
  }
  </code></pre>