从首选项标题开始活动
我正在实现 n 层 PreferenceActivities 第一层 PreferenceActivity 从首选项标头加载。
第一个标头创建设置片段,它是一个 PreferenceFragment。第二个是浏览器活动(第二个是来自developer.android.com 的示例),它打开指定的Url。第三个我希望成为 PreferenceAtivity 的下一个级别,它也将从首选项标头加载。
前两个工作正常,但第三个使应用程序崩溃,但出现异常:
“android.content.ActivityNotFoundException:找不到处理 Intent { act=android.intent.action.VIEW dat=com.mycompany.myapp.ui.MyPreferenceActivity} 的活动 “
在清单文件中声明了 MyPreferenceActivity。可能 main_headers.xml 中的活动声明是错误的,但我在参考文献中没有找到如何正确执行此操作的任何提示。尝试了几种变体,但它们不起作用。
我使用的示例:< a href="http://developer.android.com/reference/android/preference/PreferenceActivity.html">http://developer.android.com/reference/android/preference/PreferenceActivity.html
任何想法为什么它不起作用对我来说或者如何调用下一个 PreferenceActivity? 基本上我只需要从标题开始一个活动,这应该很简单,但我错过了一些东西。
public class MySettings extends PreferenceActivity
{
@Override
public void onBuildHeaders(List<Header> target)
{
loadHeadersFromResource(R.xml.main_headers, target);
}
}
main_headers.xml:
<?xml version="1.0" encoding="utf-8"?>
<preference-headers
xmlns:android="http://schemas.android.com/apk/res/android" >
<header android:title="Custom Settings"
android:fragment="com.mycompany.myapp.ui.SettingsFragment" />
<header android:title="Intent"
android:summary="Launches an Intent.">
<intent android:action="android.intent.action.VIEW"
android:data="http://www.android.com" />
</header>
<header android:title="Another Preference Activity">
<intent android:action="android.intent.action.VIEW"
android:data="com.mycompany.myapp.ui.MyPreferenceActivity" />
</header>
</preference-headers>
I'm implementing n-layer PreferenceActivities
1st layer PreferenceActivity is loaded from preference-headers.
First header creates fragment of settings which is a PreferenceFragment. Second is a browser activity (2nd is an example from developer.android.com) which opens specified Url. The third one I want to be a next level of PreferenceAtivity that also will be loaded from preference-headers.
First two work fine but 3rd is crashing an app with the exception:
"android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=com.mycompany.myapp.ui.MyPreferenceActivity}
"
MyPreferenceActivity declared in the manifest file. Probably declaration of activity in main_headers.xml is wrong, but I didn't find in references any tip how to do it correct. Tried several variations, they didn't work.
Example I used: http://developer.android.com/reference/android/preference/PreferenceActivity.html
Any thoughts why it doesn't work for me or how the next PreferenceActivity can be called?
Basically I just need to start an activity from header, that should be really simple but I'm missing something.
public class MySettings extends PreferenceActivity
{
@Override
public void onBuildHeaders(List<Header> target)
{
loadHeadersFromResource(R.xml.main_headers, target);
}
}
main_headers.xml:
<?xml version="1.0" encoding="utf-8"?>
<preference-headers
xmlns:android="http://schemas.android.com/apk/res/android" >
<header android:title="Custom Settings"
android:fragment="com.mycompany.myapp.ui.SettingsFragment" />
<header android:title="Intent"
android:summary="Launches an Intent.">
<intent android:action="android.intent.action.VIEW"
android:data="http://www.android.com" />
</header>
<header android:title="Another Preference Activity">
<intent android:action="android.intent.action.VIEW"
android:data="com.mycompany.myapp.ui.MyPreferenceActivity" />
</header>
</preference-headers>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想从第三个偏好启动显式活动,请执行以下操作:
If you want to start an explicit Activity from your third preference then do this:
并在 mainfest 文件中添加以下代码
and add the below code in mainfest file
如果您使用 java 创建首选项,那么您可以通过以下方式获得相同的结果:
if you are creating preferences using java ,then you can achieve the same result by,