Android 为什么要使用Intent.URI\u Intent\u方案

Android 为什么要使用Intent.URI\u Intent\u方案,android,android-intent,Android,Android Intent,在阅读有关小部件的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 wid

在阅读有关小部件的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://,但在这里有必要吗?

很简单


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

fas据我所知,它创建了一个指向意图本身的uri。或者更重要的是,“数据”——可以进行唯一性比较——最终包含以前设置的“额外数据”,而这些“额外数据”没有。