Switching from the PreferenceScreen to DialogPreference

My application has a settings menu, which is actually a PreferenceActivity. When it is created, if no boolean is given, I want to go to DialogPreference, which sets this.

I tried to do this with the intention, but the application power closed with this msg error:

E / AndroidRuntime (239): android.content.ActivityNotFoundException: Could not find an explicit activity class {Com.xxxx / com.xxxx.xxxxPreference}; Have you declared this activity in your AndroidManifest.xml?

How should I do it? Can I add that DialogPreference for the manifest?

+3
source share
2 answers

A DialogPreference Activity . a Preference, a Dialog .

, Preference. , DialogPreference, . , DialogPreference:

//Expose the protected onClick method
void show() {
    onClick();
}

onCreate() PreferencesActivity - , XML :

// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);

:

booleanProp = true; //set this to the value of the property you're checking     

if (! booleanProp) {
    //Find the Preference via its android:key
    //MyDialogPreference is your subclasss of DialogPreference
    MyDialogPreference dp = (MyDialogPreference)getPreferenceScreen().findPreference("dialog_preference");  
    dp.show();
}

, protected , .

- Dialog PrefenceActivity, , , Intent, , , Dialog . PreferenceActivity, XML :

<PreferenceScreen
        android:title="@string/title_of_preference"
        android:summary="@string/summary_of_preference">
    <intent android:action="your.action.goes.HERE"/>
</PreferenceScreen>
+4

Intent, Android. , :

<activity android:name=".path.to.MyActivity"/>
-1

Source: https://habr.com/ru/post/1730575/


All Articles