Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the purpose of intent categories?

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?.

like image 277
LuckyLuke Avatar asked Sep 09 '11 18:09

LuckyLuke


People also ask

What is the purpose of categories in intents?

Show activity on this post. The category's alone are useless, they are used to describe a possible target for an "implicit intent" in an intent-filter . When you know which class/activity you want to launch and use startActivity() or startActivityForResult() , it's called an "explicit intent".

What is the purpose of category in an intent filter?

Categories are used for implicit Intents. So, If your Activity can be started by an implicit Intent when no other specific category is assigned to activity, activity's Intent filter should include this category. (even if you have other categories in the Intent filter).

What are intent categories?

Intent classification is the automated categorization of text data based on customer goals.


1 Answers

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

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:

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).

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: Complete action using


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>

This listens to the ACTION_MAIN-action triggered by Androids Launcher (CATEGORY_LAUNCHER).

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

  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.

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.

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


Declaring your own categorys is possible.

This is however seldomly useful. See this question for more details: What is the purpose of a custom category or action?

like image 92
Lukas Knuth Avatar answered Oct 11 '22 07:10

Lukas Knuth