Subtracted on the Internet about creating activation settings for the application. In all the articles that I found, the addPreferencesFromResource() method was used:
public class PrefActivity extends PreferenceActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences) } } But as it turned out, this method is deprecated, which is why the question arises: how is the activation of settings created in API version 25?
UPD: I did everything as it was written to the answer, which gave @Regent, but when I try to launch the settings, the application closes, the "application stopped" window appears. PrefFragment.java:
package com.evgeniy.calc; import android.os.Bundle; import android.preference.PreferenceFragment; public class PrefFragment extends PreferenceFragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); } } PrefActivity.java:
package com.evgeniy.calc; import android.preference.PreferenceActivity; import java.util.List; public class PrefActivity extends PreferenceActivity { @Override public void onBuildHeaders(List<Header> target) { loadHeadersFromResource(R.xml.preferences, target); } @Override protected boolean isValidFragment(String fragmentName) { return PrefFragment.class.getName().equals(fragmentName); } } Call up the settings in MainActivity.java:
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_settings: startActivity(new Intent(this, PrefActivity.class)); return true; case R.id.action_about: startActivity(new Intent(this, AboutActivity.class)); return true; default: return super.onOptionsItemSelected(item); } }
addPreferencesFromResourcemust be in the Preference Fragment. This answer in English SO presents a detailed example. - Regent