android隐式广播和显式广播是什么,android – 显式意图,隐式意图和广播

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应用程序等等.所以,基本上你只是指定一般动作并询问系统“谁可以处理这个”,系统将处理其余的动作.应用程序开发人员使用这些类型的意图,因此如果设备上已经存在可以执行开发人员所需的操作,则他们不必“重新发明轮子”.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值