Android中的Intent是什么? 有人能举个例子吗? intent的类型是什么,我们为什么要使用它们? 为什么intent在Android中如此重要?


当前回答

一个Android应用程序可以包含零个或多个活动。当应用程序有多个活动时,通常需要从一个活动导航到另一个活动。在Android中,你通过所谓的意图在活动之间导航。你可以通过使用putExtra()将一些数据传递给你想要通过intent启动的活动。

其他回答

什么是意图?

它是传递给组件的一种消息或信息。它被用来启动一个活动,显示一个网页,发送短信,发送电子邮件等。

在android中有两种类型的intent:

隐式意图 明确的意图

隐式意图用于调用系统组件

例子

Intent i = newIntent(android.content.Intent.ACTION_VIEW,Uri.parse(“http://www.amazon.com”));

startActivity(i);

显式意图用于调用活动类。

例子

Intent Intent = newIntent (this, SecondActivity.class);

startActivity(intent);

你可以阅读更多

http://www.vogella.com/tutorials/AndroidIntent/article.html#intents_overview http://developer.android.com/reference/android/content/Intent.html

意图是对要执行的操作的抽象描述。它可以与startActivity一起使用来启动一个Activity,与broadcastIntent一起使用来将它发送到任何感兴趣的BroadcastReceiver组件,与startService(Intent)或bindService(Intent, ServiceConnection, int)一起使用来与后台服务通信。

欲了解更多详情,请参阅以下链接:

1). http://developer.android.com/reference/android/content/Intent.html

2) http://developer.android.com/guide/topics/intents/intents-filters.html

3). http://www.vogella.de/articles/AndroidIntent/article.html

还有更多的文章可用。

从广义上看,我们可以将Intent定义为

当一个Activity想要启动另一个Activity时,它会创建一个Object Intent指定它想要启动哪个Activity。

Intent是执行某个动作的“意图”;换句话说,

可用于从另一个应用程序组件请求操作的消息传递对象

一个意图基本上是一个信息,说你已经或想要某事发生。根据意图,应用程序或操作系统可能会监听它,并做出相应的反应。你可以把它当成是发给一群朋友的电子邮件,告诉你的朋友John去做某事,或者告诉那些可以做X(“意图过滤器”)的朋友去做X。其他人会忽略这封邮件,但是John(或那些可以做X的朋友)会对它做出反应。

为了监听广播意图(如电话铃声或收到短信),您实现了一个广播接收器,它将被传递意图。为了声明你可以处理另一个应用程序的意图,比如“拍照”,你在应用程序的manifest文件中声明一个意图过滤器。

如果你想发射一个意图去做某事,比如弹出拨号器,你发射一个意图说你会。

来自2013年Android构建者峰会上关于Android IPC/Binder框架的深入研究

在一些短小而有效的语句中可以理解其意图

Android supports a simple form of IPC(inter process communication) via intents Intent messaging is a framework for asynchronous communication among Android components (activity, service, content providers, broadcast receiver ) Those components may run in the same or across different apps (i.e. processes) Enables both point-to-point as well as publish subscribe messaging domains The intent itself represents a message containing the description of the operation to be performed as well as data to be passed to the recipient(s).

在这篇文章中,android架构师Dianne Hackborn给出了一个简单的答案,即它实际上是一个数据容器。

从android架构的角度来看:

Intent是一个用于进程间通信的数据容器。从android架构的角度来看,它是建立在Binder之上的。