Sigh, thank you all for your answers, unfortunately it was my mistake. In my onUpdate from my custom AppWidgetProvider, I was passing the wrong Id. I've switched it now to the proper Id, and each widget instance updates properly.
setTextViewText not working in IntentService
-
03-04-2022 - |
Question
The code here in onHandleIntent:
RemoteViews views = new RemoteViews(getPackageName(), R.layout.mylayout);
views.setTextViewText(R.id.txtView1, "some string");
...
Bundle bundle = intent.getExtras();
int id = bundle.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(id, views);
does not update the widget's TextView named txtView1. I've searched and searched, but it appears that everything I've done seems to match what I found.
Solution 3
OTHER TIPS
You need Handler to update UI from worker thread.
You can take help from this tutorial http://crodrigues.com/updating-the-ui-from-a-background-thread-on-android/
or alternatively you can use Asynctask
if you don't want to get into thread and handler stuff.
Asynctask
manages this stuff by itself and you can update UI in onPostExecute() method and so on..
You can read details about asynctask
in developer android site of google.
You have to update your textview in app widget development.
RemoteViews views = new RemoteViews(getPackageName(), R.layout.mylayout);
views.setTextViewText(R.id.txtView1, "some string");
thisWidget = new ComponentName(context, WatchWidget.class);
appWidgetManager.updateAppWidget(thisWidget, remoteViews);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow