Android 中的 Intent 是什么? [英] What is an Intent in Android?

查看:19
本文介绍了Android 中的 Intent 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • Android 中的 Intent 是什么?
  • 有人可以举例说明吗?
  • Intent 有哪些类型,我们为什么要使用它们?
  • 为什么 Intent 在 Android 中如此重要?

推荐答案

An Intent 是执行动作的意图";换句话说,

An Intent is an "intention" to perform an action; in other words,

一个消息对象,您可以使用它从另一个应用组件请求操作

a messaging object you can use to request an action from another app component

意图基本上是一条消息,表示您做了或希望某事发生.根据意图,应用程序或操作系统可能正在侦听它并做出相应的反应.把它想象成给一群朋友的一封爆炸性电子邮件,你告诉你的朋友约翰做某事,或者发给可以做 X 的朋友("intent filters"),做 X.其他人会忽略电子邮件,但约翰(或能做 X 的朋友)会对此做出反应.

An Intent is basically a message to say you did or want something to happen. Depending on the intent, apps or the OS might be listening for it and will react accordingly. Think of it as a blast email to a bunch of friends, in which you tell your friend John to do something, or to friends who can do X ("intent filters"), to do X. The other folks will ignore the email, but John (or friends who can do X) will react to it.

要侦听广播意图(如电话铃响或收到短信),您需要实现一个 广播接收器,它将被传递意图.要声明您可以处理其他人的应用程序意图,例如拍照",您可以声明一个 应用清单文件中的意图过滤器.

To listen for an broadcast intent (like the phone ringing, or an SMS is received), you implement a broadcast receiver, which will be passed the intent. To declare that you can handle another's app intent like "take picture", you declare an intent filter in your app's manifest file.

如果你想触发一个意图来做某事,比如弹出拨号器,你激发意图说你会.

If you want to fire off an intent to do something, like pop up the dialer, you fire off an intent saying you will.

这篇关于Android 中的 Intent 是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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