Hi Guys,
I've written a widget and attached an onClick to the whole widget following the android developer site:
App Widgets | Android Developers
But the problem is it doesn't actully bind the onClick event to the widget
AND
the strange thing is if I redeploy/reinstall the app, the old widgets have the onClick but any new ones I add do not.
This ring any bells for anyone?
I've written a widget and attached an onClick to the whole widget following the android developer site:
App Widgets | Android Developers
Code:
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
for(int i = N-1; i >= 0; i--){
final int appWidgetId = appWidgetIds[i];
setAlarm(context, appWidgetId, UPDATE_RATE);
// TODO this doesnt actually bind the onClick to the widget ARGH
// http://developer.android.com/guide/topics/appwidgets/index.html
// Create an Intent to launch MainActivity
final Intent intent = new Intent(context, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// Get the layout for the App Widget and attach an on-click listener to the button
final RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setOnClickPendingIntent(R.id.widgetLayout, pendingIntent);
// Tell the AppWidgetManager to perform an update on the current App Widget
appWidgetManager.updateAppWidget(appWidgetId, views);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
But the problem is it doesn't actully bind the onClick event to the widget
AND
the strange thing is if I redeploy/reinstall the app, the old widgets have the onClick but any new ones I add do not.
This ring any bells for anyone?