The method getPreferenceManager() is undefined for the type BatteryService in android app
<p>I am making a service so I have service class which is extended from Service. I am getting a checkbox from PreferenceScreen and based on whether it is checked or not I perform an action. To get CheckBoxPreference I use getPreferenceManager() method. But it has red underline. When I hover over it shows me this error <code>The method getPreferenceManager() is undefined for the type BatteryService</code>. When I use the same code in my main class then it works. Here is my code</p>

<pre><code>public int onStartCommand(Intent intent, int flags, int startId) {
    initNotification();

    final CheckBoxPreference checkboxPref = (CheckBoxPreference) getPreferenceManager().findPreference("cbAlarm");

    checkboxPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
                public boolean onPreferenceChange(Preference preference,
                        Object newValue) {
                    if (newValue.toString().equals("true")) {
                        Toast.makeText(getApplicationContext(), "Service Started", Toast.LENGTH_LONG).show();
                        registerReceiver(batteryInfoReceiver, new IntentFilter(
                                Intent.ACTION_BATTERY_CHANGED));
                    } else if (newValue.toString().equals("false")) {
                        stopService(new Intent(getBaseContext(),
                                BatteryService.class));
                        Toast.makeText(getApplicationContext(),
                                "Unchecked", Toast.LENGTH_SHORT).show();
                    }
                    return true;
                }
            });
    return START_STICKY;
}
</code></pre>

<p>How can I solve this problem? Help Please</p>
