Android Home Launcher,在Launcher中添加带图标的活动

时间:2015-12-11 11:39:32

标签: android android-activity android-manifest launcher android-launcher

我已经创建了一个自定义启动器,它完美正常工作。现在我想添加一个活动,它将像启动器中的任何其他应用程序一样启动。

这是我的清单文件。

 <activity
        android:name="com.sample.launcher2.Launcher"
        android:launchMode="singleTask"
        android:clearTaskOnLaunch="true"
        android:stateNotNeeded="true"
        android:resumeWhilePausing="true"
        android:theme="@style/Theme"
        android:windowSoftInputMode="adjustPan"
        android:screenOrientation="nosensor">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.MONKEY"/>
        </intent-filter>
    </activity>

    <activity 
        android:name="com.sample.launcher2.MainActivity"
        android:label="@string/application_name"
    android:icon="@mipmap/ic_launcher_home">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

我无法从启动器启动活动。我如何实现它?

2 个答案:

答案 0 :(得分:0)

Make following changes hope it will work
<activity
        android:name="com.sample.launcher2.Launcher"
        android:launchMode="singleTask"
        android:clearTaskOnLaunch="true"
        android:stateNotNeeded="true"
        android:resumeWhilePausing="true"
        android:theme="@style/Theme"
        android:windowSoftInputMode="adjustPan"
        android:screenOrientation="nosensor">
        <intent-filter>
            <action android:name="com.sample.launcher2.Launcher" />//Here the change
            <category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.MONKEY"/>
        </intent-filter>
    </activity>

    <activity 
        android:name="com.sample.launcher2.MainActivity"
        android:label="@string/application_name"
    android:icon="@mipmap/ic_launcher_home">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
           <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

答案 1 :(得分:0)

将该活动的启动模式更改为singleTask可能有所帮助!