protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Refresh testbeds list

    final ListPreference testbedslist = (ListPreference) findPreference("selecttestbed");
    SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE);
    ServerDatabaseHandler serverDatabase = new ServerDatabaseHandler(this);
    Server currentServer = serverDatabase.getServer(prefs.getInt("prefServerId", 0));
    serverDatabase.close();
    DataSource tempDS = new DataSource(currentServer);
    List<Testbed> testbeds = tempDS.getTestbeds();
    ArrayList<CharSequence> testbedName = new ArrayList<CharSequence>();
    ArrayList<CharSequence> testbedValues = new ArrayList<CharSequence>();
    int i;
    for (i = 0; i < testbeds.size(); i++) {
      testbedName.add(testbeds.get(i).getName());
      testbedValues.add(Integer.toString(i));
    }
    final CharSequence[] items = testbedName.toArray(new CharSequence[testbedName.size()]);
    final CharSequence[] values = testbedValues.toArray(new CharSequence[testbedValues.size()]);

    testbedslist.setEntries(items);
    testbedslist.setEntryValues(values);
  }
  /**
   * onCreate
   *
   * <p>Called when the activity is first created. This is where you should do all of your normal
   * static set up: create views, bind data to lists, etc. This method also provides you with a
   * Bundle containing the activity's previously frozen state, if there was one.
   *
   * <p>Always followed by onStart().
   *
   * @param savedInstanceState Bundle
   */
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences);
    setContentView(R.layout.activity_preferences);
    setTitleFromActivityLabel(R.id.title_text);

    Preference serversbutton = (Preference) findPreference("managesevers");
    serversbutton.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference arg0) {
            openServersManager();
            return true;
          }
        });

    final ListPreference testbedslist = (ListPreference) findPreference("selecttestbed");

    SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE);
    ServerDatabaseHandler serverDatabase = new ServerDatabaseHandler(this);
    Server currentServer = serverDatabase.getServer(prefs.getInt("prefServerId", 0));
    serverDatabase.close();

    DataSource tempDS = new DataSource(currentServer);
    List<Testbed> testbeds = tempDS.getTestbeds();
    ArrayList<CharSequence> testbedName = new ArrayList<CharSequence>();
    ArrayList<CharSequence> testbedValues = new ArrayList<CharSequence>();
    int i;
    for (i = 0; i < testbeds.size(); i++) {
      testbedName.add(testbeds.get(i).getName());
      testbedValues.add(Integer.toString(i));
    }
    final CharSequence[] items = testbedName.toArray(new CharSequence[testbedName.size()]);
    final CharSequence[] values = testbedValues.toArray(new CharSequence[testbedValues.size()]);

    testbedslist.setEntries(items);
    testbedslist.setEntryValues(values);

    testbedslist.setOnPreferenceChangeListener(
        new OnPreferenceChangeListener() {

          @Override
          public boolean onPreferenceChange(Preference preference, Object newValue) {
            setCurrentTestbed(newValue);
            return true;
          }
        });

    Preference clearcache = (Preference) findPreference("clearcache");
    clearcache.setOnPreferenceClickListener(
        new OnPreferenceClickListener() {
          @Override
          public boolean onPreferenceClick(Preference arg0) {
            clearCache();
            return true;
          }
        });
  }