如何在Project中仅显示Android设备中的一个MainActivity

时间:2013-01-01 04:57:34

标签: android android-activity android-manifest

我在android中创建了一个包含四个活动的Timer应用程序。现在,当我在我的Android设备上安装.apk时,它会在屏幕上显示所有四个活动图标,而不是仅显示主要活动图标。请帮助我..我清单文件如下;

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.timerdemo2"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".NewProject"
            android:label="@string/title_activity_main" 
             android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />


            </intent-filter>
        </activity>
        <activity
            android:name=".Timedetails"
            android:label="@string/title_activity_timedetails"
             android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />


            </intent-filter>
        </activity>
        <activity
            android:name=".ListActivity"
            android:label="@string/title_activity_list"
             android:screenOrientation="portrait" >
            <intent-filter>


                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_new_project"
             android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />


            </intent-filter>
        </activity>
    </application>

</manifest>

3 个答案:

答案 0 :(得分:2)

尝试使用此代码代替上述&amp;  记住Application add tag的主要活动

             <intent-filter>
                <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />    
            </intent-filter>

你的清单应该是这样的

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.timerdemo2"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".NewProject"
            android:label="@string/title_activity_main" 
             android:screenOrientation="portrait">

        </activity>
        <activity
            android:name=".Timedetails"
            android:label="@string/title_activity_timedetails"
             android:screenOrientation="portrait" >

        </activity>
        <activity
            android:name=".ListActivity"
            android:label="@string/title_activity_list"
             android:screenOrientation="portrait" >

        </activity>
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_new_project"
             android:screenOrientation="portrait" >

         <intent-filter>
                <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>
        </activity>
    </application>

</manifest>

答案 1 :(得分:1)

这是因为您将</intent-filter>应用于所有活动而不是main,只需进行如下所述的更改

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.timerdemo2"
        android:versionCode="1"
        android:versionName="1.0" >

        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="15" />

        <application
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".MainActivity"
                android:label="@string/title_activity_main" 
                 android:screenOrientation="portrait">
                <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
            </activity>

            <activity
                android:name=".NewProject"
                android:label="@string/title_activity_new_project"
                 android:screenOrientation="portrait" >

            </activity>
            <activity
                android:name=".Timedetails"
                android:label="@string/title_activity_timedetails"
                 android:screenOrientation="portrait" >

            </activity>
            <activity
                android:name=".ListActivity"
                android:label="@string/title_activity_list"
                 android:screenOrientation="portrait" >

            </activity>

        </application>

    </manifest>

There is quite a bit of documentation on intent Filter

答案 2 :(得分:0)

更改你的意图过滤器,MAIN / LAUNCHER意图过滤器实质上告诉android该活动是应用程序的启动活动 而不是使用:

<action android:name="android.intent.action.MAIN" />

使用:

<action android:name="android.intent.action.VIEW" />