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?.
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".
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).
Intent classification is the automated categorization of text data based on customer goals.
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:
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":
action
. This specifies what action the "intent filter" should
listen to.category
s. This specifies, how the activity should be
called.One of the category
s 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 category
s is possible.
This is however seldomly useful. See this question for more details: What is the purpose of a custom category or action?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With