从首选项屏幕启动活动(意图在xml文件中定义) [英] Start Activity from preference screen (intent defined in xml file)

查看:79
本文介绍了从首选项屏幕启动活动(意图在xml文件中定义)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的首选项文件中,我去了

In my preference file I go this

    <PreferenceCategory android:title="Title" >
        <Preference android:title="title" >
    <intent android:action="com.my.package.MainActivity" 
            />
</Preference>
    </PreferenceCategory>

该活动是在清单文件中创建的,但我仍然得到

The activity is created in the manifest file , but I still get

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.my.package.MainActivity }

如何从首选项屏幕开始活动?

How can I start activity from preferences screen ?

推荐答案

我遇到了同样的问题,但是我在stackoverflow上搜索的所有解决方案都没有解决我的activitynotfound异常.

I had the same issue but none of the solutions i searched on stackoverflow solved my activitynotfound Exception.

这是我从此处找到的有效解决方案:

Here is the working solution i found from here:

    <PreferenceScreen  
                android:title="@string/title_intent_preference"  
                android:summary="@string/summary_intent_preference">  

            <intent android:action="your.action.string"/>  

 </PreferenceScreen>  

在manifest.xml中的活动中设置一个意图过滤器

set an intent filter in your activity inside manifest.xml

    <activity ...>  
            <intent-filter>  
                <action android:name="your.action.string"/>  
                <category android:name="android.intent.category.DEFAULT" />  
            </intent-filter>  
</activity>

这篇关于从首选项屏幕启动活动(意图在xml文件中定义)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆