开发者

In an Android application,can more than one Main Activity exist

开发者 https://www.devze.com 2023-04-07 11:15 出处:网络
I hope someone will help. In And开发者_运维百科roid manifest file, can we specify more than one activity as the main activity?Yes you can. But you should define one as default by CATEGORY_DEFAULT.With

I hope someone will help. In And开发者_运维百科roid manifest file, can we specify more than one activity as the main activity?


Yes you can. But you should define one as default by CATEGORY_DEFAULT. Without default main activity if you have two activities, Android Market do not know what activity to start.

    <activity
        android:name=".FirstMainActivity"
        android:label="First Activity"
        android:icon="@drawable/first_icon">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name=".SecondMainActivity"
        android:label="Second Activity"
        android:icon="@drawable/second_icon">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

You have to set action=MAIN and category=LAUNCHER to be your entry point showed in launcher.


Yes you can have more than one main activity and you can have multiple launcher activities but if you do so, you will see as many icons in the applications drawer.


If you think you have several entry points in your application then why not?

0

精彩评论

暂无评论...
验证码 换一张
取 消