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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With