在发射器中创建第二个快捷方式
-
01-10-2019 - |
题
我正在Android中创建一个很酷的家庭应用程序。
由于这是一个家庭应用程序,所以我不希望她出现在所有应用程序列表中。
这很容易,但是现在我希望此应用程序的设置出现。因此,我以这种方式创建了我的应用程序的偏好:
<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);
}
}
解决方案
刚找到一些东西! (顺便说一句,当我找到自己问题的答案时,最好使用的方法是什么?我应该回答自己吗?在这里..)
我必须在明显的情况下使用它:
<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>
那效果很好!
不隶属于 StackOverflow