In Android, what is the purpose of < activity-alias > ? From the documentation, it seems that it is just another name for an existing < activity > with intent filters that override the target activity's filter (my understanding so far).
What is its practical use ?
Can a caller send an intent both to the target and the alias ?
it seems that it is just another name for an existing < activity > with intent filters that override the target activity's filter (my understanding so far).
I'd define it as "providing additional filters", more so than overriding.
What is its practical use ?
You can disable components, like <activity-alias>
. You cannot disable <intent-filter>
elements (though that'd be seriously handy).
Hence, if you have an activity that you want to be available all the time, yet only some of the time offer up a specific filter (or filters), <activity-alias>
is for you.
A modern example of this comes courtesy of the new Storage Access Framework. It used to be that to make documents available to third-party apps, you would implement an ACTION_GET_CONTENT
activity, with an <intent-filter>
advertising relevant MIME types (and, possibly, ContentProvider
paths for a provider of yours). However, if you are adopting the Storage Access Framework on Android 4.4+, you don't want to also have the ACTION_GET_CONTENT
activity available -- the net effect is that everything of yours will show up twice. So, on Android 4.4+ devices, you need to either disable the whole activity (if you do not need it for anything else), or move the ACTION_GET_CONTENT
<intent-filter>
to an <activity-alias>
, so you can disable it separately. This is covered in greater detail in the documentation.
TL;DR: I doubt that many developers use <activity-alias>
, though it has its use cases (e.g., the launcher one cited in a comment on your question).
Can a caller send an intent both to the target and the alias ?
Um, if by that, you mean "can I use startActivity()
to start either the activity or the alias?", then, yes.
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