Search code examples
androidandroid-layoutpreferenceactivity

using preference screen in daydream screensaver


I wants to launch the preference screen from the screen saver setting but when I try to app is getting force close.

I am getting error

android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.anuja.ddtrial4/com.example.abc.ddtrial4.preferenceclass}; have you declared this activity in your AndroidManifest.xml?

Here is my code

setting.xml

<?xml version="1.0" encoding="utf-8"?>
<dream xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="com.example.abc.ddtrial4/.preferenceclass"/>

preference.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">

<SwitchPreference
    android:defaultValue="false"
    android:icon="@drawable/analog1"
    android:key="switch_preference_1"
    android:switchTextOff="Digital"
    android:switchTextOn="Analog" />
</PreferenceScreen>

preferenceclass.java

public class preferenceclass extends PreferenceActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    addPreferencesFromResource(R.xml.preference);


}
}

Solution

  • ActivityNotFoundException: Unable to find explicit activity class {com.example.anuja.ddtrial4/com.example.abc.ddtrial4.preferenceclass};

    Make Sure you added this in your Manifest section

    PreferenceActivity.

    This is the base class for an activity to show a hierarchy of preferences to the user .

     <activity  android:name=".preferenceclass"
      android:theme="@android:style/Theme.Black.NoTitleBar">
    
     </activity>