Pew Labs
Pew Labs

Reputation: 809

Android Widget: OnClickPendingIntent won't Work

Why doesn't recieve get called when I click on Button wid??

Code:

public class Widget extends AppWidgetProvider {
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        for (int i = 0; i < appWidgetIds.length; i++) {
            int appWidgetId = appWidgetIds[i];

            Intent intent = new Intent(context, Widget.class);
            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

            RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
            views.setOnClickPendingIntent(R.id.wid, pendingIntent);
            appWidgetManager.updateAppWidget(appWidgetId, views);
        }
    }

     @Override
        public void onReceive(Context context, Intent intent) {
            super.onReceive(context, intent);
            Log.d("ARH","CLICKK");
        }

Becuase I need a button to manual refresh the widget but it seems that Log.d("ARH","CLICKK"); only gets called when i add the Widget.

Thanks!

Upvotes: 1

Views: 498

Answers (1)

Ran
Ran

Reputation: 4157

You using a PendingIntent to call an Activity but your Widget class is not an activity.

If you want to update to your widget, then you need to use getBroadcast that sends an APPWIDGET_UPDATE action.

Upvotes: 3

Related Questions