activity-alias 多入口配置

在android 官方给的意见是:

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 a independent entity. It can have its own set of intent filters, and they, rather than the intent filters on the target activity itself, determine which intents can activate the target through the alias and how the system treats the alias. For example, the intent filters on the alias may specify the "android.intent.action.MAIN" and "android.intent.category.LAUNCHER" flags, causing it to be represented in the application launcher, even though none of the filters on the target activity itself set these flags.

With the exception of targetActivity, <activity-alias> attributes are a subset of <activity> attributes. For attributes in the subset, none of the values set for the target carry over to the alias. However, for attributes not in the subset, the values set for the target activity also apply to the alias.

其大意是说:

这是一个activity的别名,目标activity由targetActivity属性命名,且目标activity和与别名必须在同一个应用程序中。别名将目标activity表示为独立的个体,这个独立的个体完全可以有自己的一组意图过滤器,而不是目标活动的过滤器。

语法格式

<activity-alias android:enabled=["true" | "false"]
                android:exported=["true" | "false"]
                android:icon="drawable resource"
                android:label="string resource"
                android:name="string"
                android:permission="string"
                android:targetActivity="string" >
    . . .
</activity-alias>
  1. enabled

    该属性用来决定目标Activity可否通过别名被系统实例化,默认为true。
    需要注意的是application也有enable属性,只用当它们同时为true时,activity-alias的enable才生效。

  2. exported

    该属性为true的话,则目标Activity可被其他应用调起,如为false则只能被应用自身调起。
    其默认值根据activity-alias是否包含intent-filter元素决定,如果有的话,则默认为true;没有的话则为false。
    其实也很好理解,如果有intent-filter,则目标Activity可以匹配隐式Intent,因此可被外部应用唤起;
    如果没有intent-filter,则目标Activity要被调起的话必须知道其精确类名,因为只有应用本身才知道精确类名,所以此时默认为false。

  3. icon

    允许自定义icon,可以不同于应用本身在桌面的icon。如果需要在桌面上创建快捷入口,也许产品会要求换个不同的icon。

  4. label

    该属性类似于android:icon,自定义快捷入口的名称。

  5. name

    该属性可以为任意字符串,但最好符合类名命名规范。activity元素的name属性实质上都会指向一个具体的Activity类,而activity-alias的name属性仅作为一个唯一标识而已。

  6. permission

    该属性指明了通过别名声明调起目标Activity所必需的权限。

  7. targetActivity

    该属性指定了目标Activity,即通过activity-alias调起的Activity是哪个,此属性其实类似于activity标签中的name属性,需要规范的Activity包名类名。

注意:

在AndroidManifest配置文件中,activity-alias标签元素必须声明在目标Acitvity对应的activity标签元素之后,否则会编译错误。

使用示例

<application
        android:name=".InitApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher_circle"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:enabled="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".SplashActivity"
            android:configChanges="orientation|screenSize|uiMode"
            android:label="@string/app_name"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

        <activity-alias
            android:name=".SplashActivity_circle"
            android:enabled="true"
            android:label="快捷入口"
            android:targetActivity=".SplashActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity-alias>
 </application>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值