安装应用程序后,应用程序小部件手动更新在更新后不起作用

时间:2018-07-31 05:11:34

标签: android widget

创建片段时,我将执行以下代码。但是,小部件一旦更新,便无法再次更新。

AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getContext());
                RemoteViews remoteViews = new RemoteViews(getContext().getPackageName(), R.layout.recipe_appwidget);
                ComponentName thisWidget = new ComponentName(getContext(), RecipeAppWidgetProvider.class);
                Intent intent = new Intent(getContext(), RecipeWidgetService.class);
                intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
                remoteViews.setRemoteAdapter(R.id.listViewWidget, intent);
                remoteViews.setEmptyView(R.id.listViewWidget, R.id.empty_view);
                int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
                appWidgetManager.updateAppWidget(thisWidget, remoteViews);
                appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.layout.recipe_appwidget);

0 个答案:

没有答案