Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What Is The Difference of AppCompatPreferenceActivity And SettingActivity?

I add SettingActivity on my app, and I get this auto generated java files AppCompatPreferenceActivity.java and SettingsActivity.java .

What's the difference of the two? I came across with the link below but it doesn't discuss it.

Preference

I have no idea where to code.

like image 288
RoCk RoCk Avatar asked Feb 18 '16 12:02

RoCk RoCk


1 Answers

Seems I am late to game, but anyway. HOpe this sill help.

1. Where to put your code (ANSWER)

SettingsActivity.java

Do not mess with AppCompatPreferenceActivity.java. Every thing that you want to change should be coded inside SettingsActivity.java class.

2.What is AppCompatPreferenceActivity.java (ANSWER)

Well when using settings activity the class to be created is like:

public class SettingsActivity extends PreferenceActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
    }
}

In case we want to support upper versions of Android we use

public class SettingsActivity extends AppCompatPreferenceActivity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.preferences);
        }
    }

I think you have seen this libraries android-support-v4,android-support-v7 and etc, They all are meant to support upper SDKs (e.g version over 4, 7 and so on). And this class is kind of them.

like image 94
Farid Avatar answered Nov 02 '22 15:11

Farid