【问题标题】:Android Home Launcher, add a activity with icon in LauncherAndroid Home Launcher,在 Launcher 中添加一个带有图标的活动
【发布时间】:2015-12-11 11:39:32
【问题描述】:

我创建了一个自定义启动器,它运行良好。现在我想向它添加一个活动,它应该像启动器中的任何其他应用程序一样启动。

这是我的清单文件。

 <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>

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

【问题讨论】:

  • 我之前从未构建过启动器,所以我可能错了,但您不需要Launcher 类别吗?
  • @user2340612 不需要。

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


【解决方案1】:
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" />
           <category android:name="android.intent.category.DEFAULT" />
           <category android:name="android.intent.category.HOME"/>
        </intent-filter>
    </activity>

【讨论】:

  • 这对我有用。但现在的问题是启动器没有在操作系统启动时启动......知道有什么问题吗?
  • 请在意图过滤器中添加主页和默认类别,其他选项可以是使用广播接收器并监听启动事件。我更新了代码以在意图过滤器中包含更多类别。希望对你有帮助谢谢
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-20
    • 1970-01-01
    • 2011-09-05
    • 1970-01-01
    • 2018-12-24
    • 2014-11-16
    • 2016-10-15
    相关资源
    最近更新 更多