Android 即使调用了onUpdate,AppWidget也不会更新
我发布一条广播来更新我的小部件,它的Android 即使调用了onUpdate,AppWidget也不会更新,android,widget,android-appwidget,Android,Widget,Android Appwidget,我发布一条广播来更新我的小部件,它的onUpdate函数被调用,我可以在日志中看到它,但文本保持不变——除了创建小部件时第一次调用onUpdate之外 public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { Log.d("WIDGET", "onUpdate"); RemoteViews views = new RemoteView
onUpdate
函数被调用,我可以在日志中看到它,但文本保持不变——除了创建小部件时第一次调用onUpdate之外
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Log.d("WIDGET", "onUpdate");
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_home);
views.setTextViewText(R.id.text, new Random().nextInt() + "x");
Intent intent = new Intent(context, InfoActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
// Get the layout for the App Widget and attach an on-click listener
// to the button
views.setOnClickPendingIntent(R.id.text, pendingIntent);
appWidgetManager.partiallyUpdateAppWidget(appWidgetIds, views);
Log.d("WIDGET", "updated");
}
您需要在创建appWidgetId时存储它,或者在您想要更新它时存储它。 召唤 我不知道为什么 不工作。你可以看这些文件 appWidgetManager.partiallyUpdateAppWidget(AppWidgetId,视图)