android – 显式意图,隐式意图和广播

我正在努力更好地理解意图的主题.

使用组件名称配置显式意图.在我看过的每个例子中,它都用于启动或停止组件.这是明确意图的唯一目的吗?

隐式intent没有目标组件.隐式意图也可以启动/停止组件,但它们也可以由broadcastReceivers接收.是否有其他方式可以获得隐含意图?

当操作系统发送动作设置为Action.MAIN时,这是一个明确的意图,对吧?

谢谢.

解决方法

android文档:

Explicit intents specify the component to start by name (the
fully-qualified class name). You’ll typically use an explicit intent
to start a component in your own app,because you kNow the class name
of the activity or service you want to start. For example,start a new
activity in response to a user action or start a service to download a
file in the background.

Implicit intents do not name a specific component,but instead declare
a general action to perform,which allows a component from another app
to handle it. For example,if you want to show the user a location on
a map,you can use an implicit intent to request that another capable
app show a specified location on a map.

正如您所说,显式意图用于在您的应用程序中启动活动 – 或从一个“屏幕”转换到另一个“屏幕”.显式意图可能是Intent intent = new Intent(currentContext,ActivityB.class);当您在应用程序中时,将使用这些类型的意图,并根据用户与您的活动的交互方式明确知道您要启动哪个组件.

隐式意图不直接指定应该调用Android组件,而只是指定要执行的一般操作.当您希望某些外部应用程序为您执行某些操作时,通常会使用这些.用于使用外部应用程序发送电子邮件的隐式意图的示例将是:

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL,new String[]{"someemail@gmail.com"});
i.putExtra(Intent.EXTRA_SUBJECT,"subject");
i.putExtra(Intent.EXTRA_TEXT,"body");

此意图将查询设备上安装的可以处理发送电子邮件的应用程序,但可能有相当多的应用程序可以执行此操作 – 例如,如果我们有gmail应用程序,hotmail应用程序等等.所以,基本上你只是指定一般动作并询问系统“谁可以处理这个”,系统将处理其余的动作.应用程序开发人员使用这些类型的意图,因此如果设备上已经存在可以执行开发人员所需的操作,则他们不必“重新发明轮子”.

以下是一些可能有助于更好地解释它的参考资料:

http://developer.android.com/guide/components/intents-filters.html

http://www.vogella.com/articles/AndroidIntent/article.html

相关文章

这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...