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 ?
try this
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:
set an intent filter in your activity inside manifest.xml
This isn't the right way to start an intent from xml. The
android:action
field isn't for the name of the activity you are trying to start; it describes an action for an intent-filter (such asandroid.intent.action.VIEW
orandroid.intent.action.EDIT
) that another activity can supply.See this answer for the correct use of
<intent
>, android:action, etc: https://stackoverflow.com/a/3751306/582004Make sure that in your AndroidManifest.xml, your activity contains an
<intent-filter
> with the<action
> that you are requesting in your PreferenceActivity (in the answer referenced, this isandroid.intent.action.VIEW
).You should do something like this in your intent declaration inside the preference xml:
Note:
targetPackage
should be same as thepackage
property declared inside themanifest
tag ofAndroidManifest.xml
. This is confusing sometimes, so read it again.So equivalent
AndroidManifest.xml
would have declaration like this:In your manifest :
This is the definition for your activity called [your package].MainActivity.
Also, try using a PreferenceScreen:
for more details please see this link... starting an activity from preferences.xml