EDIT: OK, so you install getBroadcast PendingIntent on your button with setOnClickPendingIntent and update (or call the update method) with the new recipient text. Your AppWidgetProvider class may be your receiver (you can catch your intention in onReceive ), otherwise you will create a new class that extends BroadcastReceiver .
EDIT2 (sample code):
I did not run / compile this code, so I hope it will not have errors. This is a simple helper method for getting a basic update, pending intent, using a special action:
public PendingIntent getRefreshPendingIntent(Context context, int appWidgetId){ Intent intent = new Intent("my.package.ACTION_UPDATE_WIDGET"); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); }
Hitting a custom action on onReceive in an overridden class of AppWidgetProvider
@Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction();
You also need to add an IntentFilter for the custom action to the manifest in the application recipient declaration.
<receiver android:name="my.package.MyWidgetProviderClass" android:label="MyWidget"> <intent-filter> <action android:name="my.package.ACTION_UPDATE_WIDGET"/> </intent-filter> </receiver>
Finally, you apply the pending intent for your RemoteViews whenever you build it, so when the button is pressed, it will send the action my.package.ACTION_UPDATE_WIDGET, which will be captured by your AppWidgetProvider, where you can (or call the method) update AppWidget
myRemoteViews.setOnClickPendingIntent(R.id.id_of_update_button, getRefreshPendingIntent(context, appWidgetId);