从首选项标题开始活动

发布于 2024-12-26 04:33:17 字数 1824 浏览 1 评论 0原文

我正在实现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

坚持沉默 2025-01-02 04:33:17

如果您想从第三个偏好启动显式活动,请执行以下操作:

<intent android:targetPackage="com.mycompany.myapp"
        android:targetClass="com.mycompany.myapp.ui.MyPreferenceActivity" />

If you want to start an explicit Activity from your third preference then do this:

<intent android:targetPackage="com.mycompany.myapp"
        android:targetClass="com.mycompany.myapp.ui.MyPreferenceActivity" />
你的背包 2025-01-02 04:33:17
 <header android:title="Intent"
    android:summary="Launches an Intent.">
<intent android:targetPackage="com.mycompany.myapp"
        android:targetClass="com.mycompany.myapp.ui.MyPreferenceActivity" /></header>

并在 mainfest 文件中添加以下代码

<activity android:name=".activities.MyActivity" 
              android:label="@string/my_activity_title"
              android:theme="@android:style/Theme.Black.NoTitleBar">
        <intent-filter>
           <action android:name="com.example.myapp.activities.MyActivity" />
           <category android:name="android.intent.category.DEFAULT" />
       </intent-filter>
    </activity>
 <header android:title="Intent"
    android:summary="Launches an Intent.">
<intent android:targetPackage="com.mycompany.myapp"
        android:targetClass="com.mycompany.myapp.ui.MyPreferenceActivity" /></header>

and add the below code in mainfest file

<activity android:name=".activities.MyActivity" 
              android:label="@string/my_activity_title"
              android:theme="@android:style/Theme.Black.NoTitleBar">
        <intent-filter>
           <action android:name="com.example.myapp.activities.MyActivity" />
           <category android:name="android.intent.category.DEFAULT" />
       </intent-filter>
    </activity>
抽个烟儿 2025-01-02 04:33:17

如果您使用 java 创建首选项,那么您可以通过以下方式获得相同的结果:

PreferenceScreen editPhoneNumbersScreen = getPreferenceManager().createPreferenceScreen(mContext);
    editPhoneNumbersScreen.setTitle(getResources().getString(R.string.change_add_emergency_numbers));
    editPhoneNumbersScreen.setSummary(getResources().getString(R.string.summary_add_no));


 Intent i = new Intent(getApplicationContext(),TargetActivity.class);
i.putExtra("change numbers", true);
        editPhoneNumbersScreen.setIntent(i);

if you are creating preferences using java ,then you can achieve the same result by,

PreferenceScreen editPhoneNumbersScreen = getPreferenceManager().createPreferenceScreen(mContext);
    editPhoneNumbersScreen.setTitle(getResources().getString(R.string.change_add_emergency_numbers));
    editPhoneNumbersScreen.setSummary(getResources().getString(R.string.summary_add_no));


 Intent i = new Intent(getApplicationContext(),TargetActivity.class);
i.putExtra("change numbers", true);
        editPhoneNumbersScreen.setIntent(i);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文