title: How to listen to listPreference, to change screen orientation?
body: <p>I have a PreferenceActivity in which I would like to have the option to change/lock the screen orientation.</p>
  
  <p>The orientation should lock <strong>only</strong> the Main Activity screen orientation</p>
  
  <p>I not sure were and how I should call the change listener.
  On the onCreate and onResume of the Main Activity seems right but I can't get it to work.</p>
  
  <p><strong>settings.xml</strong></p>
  
  <pre><code>   &lt;ListPreference     android:title="Screen orientation"
      android:summary="current: %s"
      android:key="rotation"
      android:defaultValue="1"
      android:entries="@array/listArray"
      android:entryValues="@array/listValues" /&gt;
  </code></pre>
  
  <p><strong>array.xml</strong></p>
  
  <pre><code>&lt;resources&gt;
  &lt;string-array name="listArray"&gt;
      &lt;item&gt;Auto rotate&lt;/item&gt;
      &lt;item&gt;Portrait&lt;/item&gt;
      &lt;item&gt;Landscape&lt;/item&gt;
  &lt;/string-array&gt;
  
  &lt;string-array name="listValues"&gt;
      &lt;item&gt;1&lt;/item&gt;
      &lt;item&gt;2&lt;/item&gt;
      &lt;item&gt;3&lt;/item&gt;
  &lt;/string-array&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>The Preference Activity</strong></p>
  
  <pre><code>public class MyPreferencesActivity extends PreferenceActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
  
      getFragmentManager().beginTransaction().replace(android.R.id.content, new MyPreferenceFragment()).commit();
  }
  
  public static class MyPreferenceFragment extends PreferenceFragment  {
  
      @Override
      public void onCreate(final Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          addPreferencesFromResource(R.xml.settings);
      }
  
  }
  </code></pre>
  
  <p>Links I already looked</p>
  
  <p><a href="https://stackoverflow.com/questions/38109685/how-to-create-a-listener-to-preferences-changes-in-preferences-activity">How to create a Listener to Preferences changes in Preferences activity?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5031915/adding-listeners-to-individual-listpreference-items">Adding listeners to individual ListPreference items</a></p>
  
  <p><a href="https://stackoverflow.com/questions/13596250/how-to-listen-for-preference-changes-within-a-preferencefragment">How to listen for preference changes within a PreferenceFragment?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5922781/onsharedpreferencechangelistener-not-registering-change-in-preference">OnSharedPreferenceChangeListener not registering change in preference</a></p>
  
  <p><a href="http://envyandroid.com/android-detect-preference-changes/" rel="nofollow noreferrer">http://envyandroid.com/android-detect-preference-changes/</a></p>