3

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

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

这很容易,但现在我希望显示此应用程序的设置。因此,我在 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>

这工作得很好,我在启动器中有一个额外的图标!

唯一的问题是当我点击图标时什么也没有发生。因此,我可以从应用程序中启动我的首选项:

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

 }
}
4

1 回答 1

1

刚刚发现了什么!(顺便说一句,当我找到自己问题的答案时使用的最佳程序是什么?我应该回答自己吗?在这里..)

我不得不在清单中使用它:

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

效果很好!

于 2010-08-25T14:44:57.270 回答