在Launcher中创建第二个快捷方式

时间:2010-08-25 11:09:34

标签: java android android-launcher android-homebutton

我正在Android中创建一个很酷的Home应用程序。

由于这是一款家庭应用,我不希望她出现在所有应用程序列表中的Launcher中。

这很简单,但现在我想要显示此应用程序的设置。所以,我在Manifest中以这种方式创建了我的应用程序的首选项:

<activity android:name=".Preferences" android:label="@string/application_name">
<intent-filter>
       <action android:name="android.intent.action.MAIN" />
       <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
</activity>

这项工作非常顺利,我在Launcher中有一个额外的图标!

唯一的问题是当我点击图标时没有任何反应。因此,我可以在应用程序中启动我的首选项:

final Intent preferences = new Intent(Launcher.this,Preferences.class);        
menu.add(0, MENU_PREFERENCES, 0, R.string.application_name).setIcon(
        R.drawable.ic_menu_preferences).setAlphabeticShortcut('F').setIntent(
          preferences);

那么,为什么启动器中的快捷方式完全没用并且没有启动任何东西?

此处有更多信息:

从应用程序内启动时记录(首选项已启动,完美运行):

08-25 13:13:03.009: INFO/ActivityManager(63): Starting activity: Intent { cmp=com.myapp.home/.Preferences }

当我从启动器启动时(没有任何反应):

08-25 13:13:45.489: INFO/ActivityManager(63): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.myapp.home/.Preferences }

我的活动:

public class Preferences extends PreferenceActivity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  addPreferencesFromResource(R.xml.preferences);

 }
}

1 个答案:

答案 0 :(得分:1)

刚找到的东西! (顺便说一下,当我找到自己问题的答案时,最好的程序是什么?我应该自己回答吗?这里......)

我必须在Manifest中使用它:

      <activity android:clearTaskOnLaunch="true" android:launchMode="singleTask" android:stateNotNeeded="true" (...other parameters...)>

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

这项工作非常好!