I love android and I have problems updating appwidget. This is a news widget that displays different text every 20 seconds. I have no problem getting the text to switch and display correctly when the widget is initialized. However, after every 30 minutes of updating the widget, my widgetID int array retains the int that existed before the update. Therefore, after each update, the widget shows old data and new data. Is there to clear the array of widget IDs of old data during the update process. Any help is appreciated.
My code is:
allWidgetIds2 = appWidgetManager.getAppWidgetIds(thisWidget);
A way to switch text to a widget. At first, this works fine, but after the update, the old data is displayed along with the new data ...
public void updateStory() { tickerheadline = RssReader.rssheadline.get(storyCounter); tickerstory = RssReader.rssstory.get(storyCounter); remoteViews.setTextViewText(R.id.headline, tickerheadline ); remoteViews.setTextViewText(R.id.story, tickerstory ); if (storyCounter==RssReader.rssheadline.size()-1){ storyCounter = 0; storyCounter++; }else{ storyCounter++; } appWidgetManager.updateAppWidget(allWidgetIds, remoteViews);
EDIT
public void updateStory() { //Added appWidgetManager = AppWidgetManager.getInstance(this.getApplicationContext()); ComponentName thisWidget = new ComponentName(getApplicationContext(),MyWidgetProvider.class); remoteViews = new RemoteViews(this.getApplicationContext().getPackageName(),R.layout.widget1); tickerheadline = RssReader.rssheadline.get(storyCounter); tickerstory = RssReader.rssstory.get(storyCounter); remoteViews.setTextViewText(R.id.headline, tickerheadline ); remoteViews.setTextViewText(R.id.story, tickerstory ); if (storyCounter==RssReader.rssheadline.size()-1){ storyCounter = 0; storyCounter++; }else{ storyCounter++; } appWidgetManager.updateAppWidget(thisWidget, remoteViews); //appWidgetManager.updateAppWidget(allWidgetIds, remoteViews); //Log.e("Widget", allWidgetIds.toString()); mHandler.postDelayed(new Runnable() { public void run() { updateStory(); } } ,20000); } }
source share