Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

android - Two launchers for a single activity

Is it possible to have multiple app icons which start the same Activity with different intent extras ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is no way to provide intent extras when launching the activity (via the Launcher).

However, what you can do is use <activity-alias> tags that define additional app icons that will launch the same (target) activity.

EDIT: Add example:

This example shows a real activity call MyRealActivity and an alias called Blahblah. Both have intent-filters that will make them appear on the list of available apps. They have different labels and different icons so that they will look like 2 different apps to the user. However, they both launch the same activity. Please note that there is no java class for .Blahblah, that is just a placeholder and must be unique.

    <activity
            android:name=".MyRealActivity"
            android:label="@string/header_application"
            android:icon="@drawable/icon_myapp">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

    <activity-alias
            android:targetActivity=".MyRealActivity"
            android:name=".Blahblah"
            android:label="@string/header_blahblah"
            android:icon="@drawable/icon_blahblah">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity-alias>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...