在阅读 Android Widget 文档时,我偶然发现了这段代码,其目的是启动一个服务以检索 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://,但这里是否有必要呢?