1

Possible Duplicate:
Using PreferencesActivity from a widget?

I have a widget with an associated PreferenceActivity/PreferenceScreen. I would like to update my widget whenever the user is finished setting the preferences.

I am using onBackPressed in my PreferenceActivity, which is being called, but the widget's onUpdate is not being called. Can anyone shed any light on this please?

public void onBackPressed() {
 if (CONFIGURE_ACTION.equals(getIntent().getAction())) {
  Intent intent=getIntent();
  intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
  Bundle extras=intent.getExtras();

   if (extras!=null) {
    int id=extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    AppWidgetManager mgr=AppWidgetManager.getInstance(this);
RemoteViews views=new RemoteViews(getPackageName(), R.layout.widget);

mgr.updateAppWidget(id, views);

Intent result=new Intent();

result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id);
setResult(RESULT_OK, result);
sendBroadcast(new Intent(this, WidgetProvider.class));
   }
  }
  super.onBackPressed();
 }
Community
  • 1
  • 1
  • this is sad that it was closed -- the answer to the older duplicate is inadequate -- i wish the older question was closed and this remained to attract better answers (fresh questions get more attention) – necromancer Dec 18 '11 at 23:00

0 Answers0