Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start Activity from preference screen (intent defined in xml file)

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 ?

like image 939
Lukap Avatar asked Feb 11 '13 10:02

Lukap


People also ask

What is PreferenceFragment?

In Android apps, there are often settings pages that contain different options the user can tweak. The PreferenceFragment and PreferenceFragmentCompat contains a hierarchy of preference objects displayed on screen in a list. These preferences will automatically save to SharedPreferences as the user interacts with them.

How do I set extra intent?

Using putExtra() We can start adding data into the Intent object, we use the method defined in the Intent class putExtra() or putExtras() to store certain data as a key value pair or Bundle data object. These key-value pairs are known as Extras in the sense we are talking about Intents.


2 Answers

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>  

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>
like image 70
Mehdi Fanai Avatar answered Sep 21 '22 18:09

Mehdi Fanai


try this

 <intent android:targetPackage="your.package"
 android:targetClass="your.package.yourMainClassName"/>
like image 21
tarik203 Avatar answered Sep 19 '22 18:09

tarik203