putExtra()和使用setData之间差() [英] Difference between putExtra() and setData()

查看:205
本文介绍了putExtra()和使用setData之间差()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是putExtra()和使用setData()之间的区别?我已阅读了android文档,但它是没有太大的帮助。
也有一个previous问题 Intent.setData VS Intent.putExtra 但目前仍不清楚。
先谢谢了。

What is the difference between putExtra() and setData()? I have read the android docs but it is of not much help. Also there is a previous question Intent.setData vs Intent.putExtra but it is still not clear. Thanks in advance.

推荐答案

使用setData()

设置此意图上运行的数据。此方法会自动清除所有类型,是previously通过的setType(String)或setTypeAndNormalize(字符串)。

Set the data this intent is operating on. This method automatically clears any type that was previously set by setType(String) or setTypeAndNormalize(String).

注意的:在Android框架方案的匹配是大小写敏感的,不像正式的RFC。因此,你应该总是以小写计划写你的开放的我们,或使用normalizeScheme()或setDataAndNormalize(URI),以确保该计划被转换为小写。

Note: scheme matching in the Android framework is case-sensitive, unlike the formal RFC. As a result, you should always write your Uri with a lower case scheme, or use normalizeScheme() or setDataAndNormalize(Uri) to ensure that the scheme is converted to lower case.

参数

数据:URI中的数据,这个​​意图现在把

data: The Uri of the data this intent is now targeting.

意图被用于发信号通知已经发生了某些事件Android系统。意图常常描述了应执行,并提供在其上应做这样的动作数据的动作。例如你的应用程序可以通过一个意图一定URL的浏览器组件启动。这是通过下面的例子证明。

Intents are used to signal to the Android system that a certain event has occurred. Intents often describes the action which should be performed and provide data on which such an action should be done. For example your application can start via an intent a browser component for a certain URL. This is demonstrated by the following example.

    String url = "http://www.google.com";
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    startActivity(i); 

但如何Android系统识别可以在一定的意图做出响应的组件?

But how does the Android system identify the components which can react to a certain intent?

有关此意图滤波器的概念被使用。一个意图过滤器指定了一个活动,服务或广播接收器可以应对各类意图的。它声明因此组件的能力。

For this the concept of an intent filter is used. An intent filter specifies the types of intents to which that an activity , service, or broadcast receiver can respond to. It declares therefore the capabilities of a component.

Android组件注册意图过滤器,静态的在AndroidManifest.xml或在广播接收机的情况下,也通过动态code。一个意图过滤器是由它的类别,操作和数据过滤器定义。它也可以包含额外的元数据

Android components register intent filters either statically in the AndroidManifest.xml or in case of a broadcast receiver also dynamically via code. An intent filter is defined by its category, action and data filters. It can also contain additional metadata.

如果一个意图是发送到Android系统,Android平台运行,使用的数据包含在Intent对象,接收器的决心。在此它确定哪些已注册的意图的数据的组件。如果几个组件已经注册了同一个意图过滤器,用户可以决定哪个组件应启动。

If an intent is send to the Android system, the Android platform runs, using the data included in the Intent object, an receiver determination. In this it determines the components which are registered for the data of the intent. If several components have registered for the same intent filter the user can decide which component should be started.

putExtra()

扩展的数据添加到意图。

Add extended data to the intent.

参数的:

名称:额外的数据的名称

name: The name of the extra data.

值:字符串数组数据值

返回相同的Intent对象,对链接多个呼叫到一个单独的语句。

Returns the same Intent object, for chaining multiple calls into a single statement.

这篇关于putExtra()和使用setData之间差()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆