Launcher stuttering when setting TextView on a Widget
Basically, after a while my widg开发者_StackOverflow社区et starts to cause the Launcher to stutter. After doing some profiling, logging, commenting out, and just good old visual inspection, I have narrowed down the problem area to updating the widget text. This is the method I am using to do this:
public static void setText(Context context, String text) {
if (appWidgetManager == null)
appWidgetManager = AppWidgetManager.getInstance(context);
RemoteViews remoteViews = Widget.getView(context);
ComponentName thisWidget = new ComponentName(context, Widget.class);
remoteViews.setTextViewText(R.id.PrimaryWidgetButton, text);
appWidgetManager.updateAppWidget(thisWidget, remoteViews);
}
The odd thing is, it takes a few minutes before it starts to cause the lag, as if there's some sort of lingering side-effect from this code. Removing the widget stops the stuttering, even though this code is still being called. Re-adding the widget resumes the stuttering immediately.
Note: The stuttering only occurs when the text is changed. So after it changes the text, the launcher is fine, but during the adjustment it stutters.
What could be causing this stuttering? Is there a better way to update text on a widget?
精彩评论