I have a flashlight app with a widget. The widget is used to turn the flashlight on and off and does not display main activity or anything. After a few hours, however, the w
Alright guys, I finally got time to fix this problem once and for all :)
I created more methods for the provider instead of doing everything in onUpdate, one important method needed:
public static PendingIntent buildButtonPendingIntent(Context context) {
Intent intent = new Intent();
intent.setAction("COM_FLASHLIGHT");
return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
And this method is called through the receiver when the widget is clicked using the code below:
private void turnFlash(Context context) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.appwidget_layout);
views.setOnClickPendingIntent(R.id.imageButton, WidgetProvider.buildButtonPendingIntent(context));
}
That is all, no more hiccups!
Look for this post, I think this problem is explained here the dark side of app widgets