I'm writing an SDK and would like developers to be able to create an activity-alias
whose targetActivity
is set to an activity inside my SDK. I'm doing this because I'd like them to be able to customize the intent filter on a specific activity in the SDK. If in the sdk's manifest there is ActivityX, I'd like them to be able to write an activity-alias
like this in their app's manifest:
<activity-alias
android:name="abc"
android:targetActivity="ActivityX">
<intent-filter>
... user's custom intent filter
</intent-filter>
</activity-alias>
The problem I'm coming across is that the targetActivity
has the restriction that it:
"... must match the name attribute of an activity element that precedes the alias in the manifest."
This is a problem because no matter where I place the activity in the sdk's manifest or where I place the alias in an example app's manifest, the alias always comes before the activity in the final merged manifest causing an INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
error.
One idea is to put an alias without an intent filter just after ActivityX is declared in the sdk manifest and hope that the two aliases will be merged together and stay in the sdk alias's position. But I can't figure out how to do that. One reason that might not be working is that two aliases may not be able to conflict.
Do you have thoughts on solving this via a merge solution or some other technique?
description: An alias for an activity, named by the targetActivity attribute. The target must be in the same application as the alias and it must be declared before the alias in the manifest. The alias presents the target activity as an independent entity.
The <activity-alias> is used to launch an Activity by preserving the launchers. So, by using the <activity-alias> you can change your Launcher Activity and the shortcut launcher will also be preserved on the home screen.
Activity alias represents a symlink to an Activity. The most popular use of activity alias is to prevent the removal of the app launcher shortcut when the underlying launcher activity is changed.
To declare your activity, open your manifest file and add an <activity> element as a child of the <application> element. For example: <manifest ... > The only required attribute for this element is android:name, which specifies the class name of the activity.
An identical issue was brought up in the AOSP. A workaround to the problem is described there as follows:
Manually include the manifest entry for the Activity from [the sdk] in the manifest of the application project, placing it before the activity-alias entry.
Despite the fact that this workaround has the problem of
... duplicate code across manifests.
it seems that the project maintainers deemed this solution as adequate. There is no indication that a fix to the underlying problem will be released any time soon.
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