title: infinite loop in android preferences
body: <p>I'm getting an infinite loop in my Android preferences and I can't point my finger on the problem.
  Help? Someone?</p>
  
  <pre><code> public class Preferences extends PreferenceActivity implements OnSharedPreferenceChangeListener{
  
  protected TextView title;
  protected ImageView icon;
  protected ImageView increase_font, decrease_font;
  ArrayList&lt;String&gt; citiesForArray = new ArrayList&lt;String&gt;();
  String[] cities;
  HashMap&lt;String, double[]&gt; locations = new HashMap&lt;String, double[]&gt;();
  ListPreference lp;
  CheckBoxPreference cb;
  AlertDialog.Builder builder;
  Intent intent, browserIntent, helpBrowserIntent;
  public static boolean noSplash;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);  
  
      if(Start.portraitOnly)
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); ///Determine the layout to portrait mode
  
      Start.afterSettings = true;
  
      reDraw();
  }
  
  
  //redraws the screen
  void reDraw()
  {           
      if(Start.hebLayout)
          addPreferencesFromResource(R.layout.preferences_heb);
      else
          addPreferencesFromResource(R.layout.preferences);
  
      this.setPreferenceScreen(getPreferenceScreen());
  
      // Set up a listener whenever a key changes            
      getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
  
      lp = (ListPreference)findPreference("location");
      lp.setEnabled(!Start.gps);
      handleValues();
  
      lp = (ListPreference)findPreference("mode");
      //lp.setEnabled(false);
  
      cb = (CheckBoxPreference)findPreference("mazon");
      if(Start.silent != 1)
          cb.setEnabled(true);
      else
          cb.setEnabled(false);
  
      cb = (CheckBoxPreference)findPreference("InStart");
      if(Start.silent != 1)
          cb.setEnabled(true);
      else
          cb.setEnabled(false);
  
      builder = new AlertDialog.Builder(Preferences.this);
      Preference about = (Preference)findPreference("about");
      about.setOnPreferenceClickListener(new OnPreferenceClickListener() {
  
          public boolean onPreferenceClick(Preference preference) {
              // TODO Auto-generated method stub
              builder.setTitle(Start.hebLayout ? "אודות" : "About")
                  .setMessage(Start.hebLayout ? R.string.hebAbout : R.string.englishAbout)
                  .setPositiveButton("OK", null)
                  .show();
              return false;
          }
      });
  
      about = (Preference)findPreference("help");
      about.setOnPreferenceClickListener(new OnPreferenceClickListener() {
  
          public boolean onPreferenceClick(Preference preference) {
              // TODO Auto-generated method stub
              startActivity(new Intent(Preferences.this, Help.class));
              return false;
          }
      });
  
      about = (Preference)findPreference("extHelp");
      browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://karriapps.blog.com/2011/04/14/siddur-guide/"));
      about.setOnPreferenceClickListener(new OnPreferenceClickListener() {
  
          public boolean onPreferenceClick(Preference preference) {
              // TODO Auto-generated method stub
              startActivity(browserIntent);
              return false;
          }
      });
  
      about = (Preference)findPreference("bug");
      browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://spreadsheets.google.com/spreadsheet/viewform?hl=en_US&amp;formkey=dEtoaEhoTWFZWU1tQWdQcGh3akRFbkE6MQ#gid=0"));
      about.setOnPreferenceClickListener(new OnPreferenceClickListener() {
  
          public boolean onPreferenceClick(Preference preference) {
              // TODO Auto-generated method stub
              startActivity(browserIntent);
              return false;
          }
      });
  
      about = (Preference)findPreference("more");
      intent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:\"Karri Apps\""));
      about.setOnPreferenceClickListener(new OnPreferenceClickListener() {
  
          public boolean onPreferenceClick(Preference preference) {
              // TODO Auto-generated method stub
              startActivity(intent);
              return false;
          }
      });
  }
  
  
  
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
          String key) {
  
      int temp;
  
      if(key.contains("rtl"))
          Start.rtl_fix = sharedPreferences.getBoolean(key, false);
      if(key.contains("pasuk"))
          Start.pasuk = sharedPreferences.getString(key, "");
      if(key.contains("sick"))
      {
          String tempo = sharedPreferences.getString(key, ""); 
          Start.sick = tempo == "  " ? "" : tempo;
      }
      if(key.contains("hebLayout"))
      {
          boolean heb = sharedPreferences.getString(key, "").contains("true") ? true : false;
          Start.hebLayout = heb;
      }
      if(key.contains("font"))
      {
          temp = Integer.parseInt(sharedPreferences.getString(key, "0"));
          Start.font = temp;
      }
      if(key.contains("sizeFont"))
      {
          temp = Integer.parseInt(sharedPreferences.getString(key, "16"));
          Start.fontSize = temp;
      }
      if(key.contains("silent"))
      {
          temp = Integer.parseInt(sharedPreferences.getString(key, "2"));
          Start.silent = temp;
      }
      if(key.contains("mazon"))
          Start.silentInMazon = sharedPreferences.getBoolean(key, false);
      if(key.contains("InStart"))
          Start.silentInStart = sharedPreferences.getBoolean(key, false);
      if(key.contains("awake"))
          Start.keepAwake = sharedPreferences.getBoolean(key, false);
      if(key.contains("port"))
          Start.portraitOnly = sharedPreferences.getBoolean(key, true);
      if(key.contains("theme"))
      {
          Start.theme = Integer.parseInt(sharedPreferences.getString(key, "0"));
          if(Start.theme == consts_theme.MODERN)
              Start.colorZmanimRight = Color.rgb(0, 238, 238);
          else
              Start.colorZmanimRight = Color.GREEN;
      }
      if(key.contains("nusach"))
      {
          temp = Integer.parseInt(sharedPreferences.getString(key, "0"));
          Start.nusach = temp;
      }
      if(key.contains("mode"))
      {
          temp = Integer.parseInt(sharedPreferences.getString(key, "0"));
          Start.mode = temp;
      }
      if(key.contains("mizrochnik"))
          Start.mizrochnik = sharedPreferences.getBoolean(key, false);
      if(key.contains("gps"))
      {
          Start.gps = sharedPreferences.getBoolean(key, true);
  
          String city = sharedPreferences.getString("location", "");
          if(!Start.gps)
              handleLocations(city);
      }
      if(key.contains("location"))
      {
          String city = sharedPreferences.getString("location", "");
          handleLocations(city);
      }
  
      getPreferenceScreen().removeAll();
  
      reDraw();       
  }
  
  private void handleValues()
  {
      readCSV();
      lp.setEntries(cities);  
      lp.setEntryValues(cities);
  }
  
  protected void handleLocations(String city)
  {       
  
      Start.lng = locations.get(city)[1];
      Start.lat = locations.get(city)[0];
      Start.locationName = city;
      Start.saveSettings(this);
  
      noSplash = true;
      if(!Splash.fromSplash)
      {
          Splash s = new Splash();
          s.checkSpecial();
      }
  }
  
  /***
   * Reading the cities file from CSV
   */
  protected void readCSV()
  {
      InputStream is = null;
      BufferedReader br = null;
  
      is = Preferences.this.getResources().openRawResource(R.raw.worldcities);
  
      br = new BufferedReader(new InputStreamReader(is));
  
      String line = "";
  
      int count = 0;
  
      try {
          while((line = br.readLine()) != null)
          {
              String[] rowData = line.split(",");
  
              citiesForArray.add(rowData[Cities.cityNice] + ", " + rowData[Cities.country]);
  
              double[] temp = new double[2];
  
              temp[0] = Double.parseDouble(rowData[Cities.Latitude]);
              temp[1] = Double.parseDouble(rowData[Cities.Longitude]);
  
              locations.put(rowData[Cities.cityNice] + ", " + rowData[Cities.country], temp);
  
              count++;
          }
  
          cities = new String[count];
          for(int i=0; i &lt; count; i++)
          {
              cities[i] = citiesForArray.get(i);
          }
  
          br.close();
          is.close();
  
      } catch (IOException e) {}
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I've ran this is a debug mode and I saw that it's just keep getting to every key without me touching it. 
  What could be the cause?</p>