什么是意向类别的目的是什么? [英] What are the purpose of intent categories?

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

问题描述

可能有人请解释一下我的意图类的目的是什么?我应该让我自己的设计呢?唯一多数民众赞成在写关于意图在我的书的类别是,他们能组的意图?

Could someone please explain me the purpose of Intent categories? When should I make my own and so on? The only thing thats written about Intent categories in my book is that they can group intents?.

推荐答案

类别的单独是没有用的,它们被用来描述一个可能的目标为意图过滤隐含意图

The category's alone are useless, they are used to describe a possible target for an "implicit intent" in an intent-filter.

当你知道类/活动要启动和使用的 startActivity() startActivityForResult(),这就是所谓的明确意图。

When you know which class/activity you want to launch and use startActivity() or startActivityForResult(), it's called an "explicit intent".

下面是一个比喻的隐含意图是如何工作的:

Here's an analogy for how implicit intents work:

想象一下,所有的应用程序坐在一间大屋子,无所事事。   然后,其他应用程序,比方说Dropbox的,需要有人来开   PDF文件。 Dropbox的应用程序进入到系统中,并说:嘿,有人   需要打开该PDF文件...(这是发送隐含的意图)。

Imagine all your applications sitting in a big room and doing nothing. Then, another application, let's say Dropbox, needs someone to open a PDF file. The Dropbox app goes to the system and says "Hey, somebody needs to open this PDF file..." (This is sending the implicit intent).

现在,系统进入了房间,并大叫你哪一个可以   显示PDF文件?,可以站起来的应用程序和   系统发现它们(这些应用程序有一个活动与匹配   意图类)。

The system now goes to the room and yells "Which one of you can display a PDF file?". The applications that can stand up and the system sees them (these applications have an activity with a matching intent category).

然后,它为您提供了一个对话框,在其中您可以选择之一   应用:使用完整的行动

It then offers you a dialog, in which you can choose one of the applications:

如果你想使你的一些活动/ BroadcastReceivers /服务的提供之外的应用范围,你可以使用Android清单申报的意图过滤器来了,所以它被打开时,系统或应用程序启动一个隐含的意图相匹配。


If you want to make some of your Activity/BroadcastReceivers/Services available outside of your applications bounds, you can use the Android Manifest to declare an "intent filter" to it, so it gets opened when the system or an app launches an "implicit intent" that matches.

您对哪些应该从启动开幕活动做到这一点(例如):

You do this (for example) for the Activity which should be opened from the launcher:

<activity android:name=".SomeActivity">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

这监听<一个href="http://developer.android.com/reference/android/content/Intent.html#ACTION_MAIN"><$c$c>ACTION_MAIN-action由机器人启动(<一个触发href="http://developer.android.com/reference/android/content/Intent.html#CATEGORY_LAUNCHER"><$c$c>CATEGORY_LAUNCHER).

您在你的意图过滤器两个子元素:

You have two child-elements in your "intent filter":

  1. 动作。这指定什么行动的意图过滤器应 听。
  2. 在一个或多个秒。这个规定,活动应该如何 调用。
  1. The action. This specifies what action the "intent filter" should listen to.
  2. One or multiple categorys. This specifies, how the activity should be called.

其中 S能(例如) android.intent.category.DEFAULT ,它告诉该活动将在全屏幕模式下正常启动。该 android.intent.category.TAB -category例如宣布这项活动作为一个<一个标签href="http://developer.android.com/reference/android/app/TabActivity.html"><$c$c>TabActivity,所以它只能被打开一个标签。

One of the categorys can be (for example) android.intent.category.DEFAULT, which tells the Activity to be launched normally in full-screen-mode. The android.intent.category.TAB-category for example declares this activity as a tab in a TabActivity, so it can only be opened as a Tab.

另一个例子是添加 android.intent.category。preFERENCE -category,这将申报活动为您设置-活动。

Another example would be adding the android.intent.category.PREFERENCE-category, which would declare the activity as your Settings-Activity.

声明自己的 s是既不可能,也无必要。

Declaring your own categorys is neither possible nor necessary.

更进一步,你需要明白,这些事件是由系统/另一个应用程序触发,只能指定是否以及如何你想它们被触发时作出反应。

Further more you'll need to understand that those events are triggered by the System/Another App and you can only specify if and how you want to react when they are triggered.

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

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