I have defined an App Widget (AppWidgetProvider, etc.), and I want to write an ad hoc program for the onClick of one of the buttons in the App Widget. The documentation describes how to inflate a layout for the App Widget and how to set a particular action on a button (see RemoteViews.setOnClickPendingIntent()), but I don’t see a way to write an ad hoc OnClickListener() for the button in the way that we do for buttons in Activities.
I have defined an App Widget ( AppWidgetProvider , etc.), and I want to
Share
Short answer: you can’t. App Widgets are lightweight — Android does not want App Widgets to run ad hoc code because that code could slow down the App Widget framework. Instead, AppWidgetProviders are supposed to do the work of App Widgets. The communication between AppWidgetProvider and AppWidget is a) the provider can update the widget with a new layout and b) the elements of that layout can send intents, which the AppWidgetProvider or other Android components can intercept and process.
See Adding behavior to individual items for an example of the AppWidgetProvider defining a custom Intent that it intercepts from its App Widget.
@Shubh: I edited your original question to make it clearer — if you like the edit, you’ll need to permit the edit so that others can see it.