在启动器中创建第二个快捷方式
我正在 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);
}
}
I'm creating a cool Home application in Android.
As this is a Home app I don't want her to appear in the Launcher, in the list of all applications.
That's pretty easy, but now I would like the settings of this application to appear. So, I created the preferences of my application this way in the 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>
That work pretty well and I have an extra icon in the Launcher!
The only problem is that nothing happens when I click on the Icon. Therefore, I can launch my Preferences from within the application:
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);
So, why is the shortcut in the launcher totally useless and does not launch anything?
More informations here:
Log when I launch from within the application (preferences are launched, worked flawlessly):
08-25 13:13:03.009: INFO/ActivityManager(63): Starting activity: Intent { cmp=com.myapp.home/.Preferences }
When I launch from the launcher (nothing happens):
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 }
My activity:
public class Preferences extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚刚发现了一些东西!
(顺便说一句,当我找到自己问题的答案时,最好使用什么程序?我应该回答自己吗?在这里..)
我必须在清单中使用它:
效果很好!
Just found something!
(And btw, what is the best procedure to use when I found an answer to my own question? Should I answer myself? here..)
I had to use that in Manifest:
That work pretty well!