在阅读有关 Widgets 的 Android 文档时,我偶然发现了这段代码,其目的是启动一项服务来检索 StackView 项目的工厂。
// Set up the intent that starts the StackViewService, which will
// provide the views for this collection.
Intent intent = new Intent(context, StackWidgetService.class);
// Add the app widget ID to the intent extras.
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
// Instantiate the RemoteViews object for the App Widget layout.
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
// Set up the RemoteViews object to use a RemoteViews adapter.
// This adapter connects
// to a RemoteViewsService through the specified intent.
// This is how you populate the data.
rv.setRemoteAdapter(appWidgetIds[i], R.id.stack_view, intent);
你可以在这里找到
我无法理解您为什么需要致电
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
我知道它给 URI 一个前缀intent://,但这里有必要吗?