为什么要使用 Intent.URI_INTENT_SCHEME?

7

在阅读 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://,但这里是否有必要呢?


据我所了解,它创建一个指向意图本身的URI。 - njzk2
或者更准确地说,"数据"——这些数据被用来比较唯一性——最终包含了之前设置的不包含在内的"额外信息"。 - Melinda Green
1个回答

0

这很容易。

简介:如果不使用setData,它将为所有小部件的实例显示相同的ID。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接