I’m reading Beginning Android Application Development by Wei-Mung Lee. I’m confused about custom actions and categories.
Here’s some code from one example. The action is a package name. The only time that it’s ever referred to ever again is in
Intent i = new Intent( "net.learn2develop.MyBrowser" );
to start an activity. How is it that this action, which is basically a package name, can know to start an activity? Just because it’s inside the activity tag?
The same thing with the category tag (different example):
<intent-filter>
<action android:name=”android.intent.action.VIEW” />
<action android:name=”net.learn2develop.MyBrowser” />
<category android:name=”android.intent.category.DEFAULT” />
<category android:name=”net.learn2develop.Apps” />
<data android:scheme=”http” />
</intent-filter>
net.learn2develop.Apps is a name that was made up by the author. It really has no meaning, right? What purpose does it serve?
Because the
<intent-filter>of the activity advertised that it can be started via that action string. BTW, just because it’s written like a package name does not mean it has to be a package name (e.g.,android.intent.action.VIEWis not a package). The package naming convention is to prevent accidental collisions with other installed apps.Well, it probably meant something to the author, though I couldn’t tell you what, exactly.
In normal Android development, you would not create a custom category. I cannot recall ever seeing one, and I’ve been doing Android development for quite a while now.
Categories are usually used to distinguish different use cases. For example, perhaps the second-most-popular category besides
DEFAULTisBROWSABLE. Activities supporting theVIEWaction in theBROWSABLEcategory become eligible to be used from links in a Web browser. So, if I had an activity forVIEW/BROWSABLEand a MIME type ofapplication/pdf, and the user clicked on a link to a PDF file in a browser, I could be chosen to view the PDF. However, if I lackedBROWSABLEas a category, then I would not be eligible for that link. Usually, an activity would only advertiseBROWSABLEif it could retrieve an HTTP URL.Off the top of my head, I cannot think of a scenario where I’d use a custom category, though.