Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start activity from 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>
like image 496
Maxim Avatar asked Jan 10 '12 20:01

Maxim


2 Answers

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" />
like image 162
gngr44 Avatar answered Oct 08 '22 03:10

gngr44


 <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>
like image 29
Waleed A. Elgalil Avatar answered Oct 08 '22 04:10

Waleed A. Elgalil