My widget application only works if I install the widget add it to the screen and then install it again, if i add another widget i have to install again in order for the second one to start working (rebooting the device also helps, after the reboot all the widgets on the screen work, I have config file, and it does not reach my appWidgetProvider (the action is set on the onUpdate method), how can i force my APP to update the widget from the configuration file?
my entire project: https://github.com/vlad1001/Widget
Thanks!
The only difference is see on your code is that your are finishing the activity before updating the widget. From documentation, the onUpdate method will not be called the first time. I think that your have to add the following:
super.onCreate(icicle);
setResult(RESULT_CANCELED);
Remove this line:
setResult(RESULT_CANCELED, resultValue);
After that, change the call to update before setResult and finish():
//make the update before finish()
appWidgetManager.updateAppWidget(appWidgetId, views);
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
setResult(RESULT_OK, resultValue);
finish();
I have not reproduce your issue, please let me know if this work for you.
After you share the source code, the base issue, is that on the first creation you are adding click intent to Text and on the update you add the pending intent to your imageView... changing this line resolve your issue. Test on the PR...
views.setOnClickPendingIntent(R.id.example_widget_imageview, clickPendingIntent);