title: Android: How to store array of strings in SharedPreferences for android
body: <p>I'm building an app which searches the web using search engine. I have one edittext in my app from which user will search the web. I want to save the search keywords just like browser history does. I'm able to save and display it with the last keyword but I can't increase the number of searches result. I want to display the last 5 searhes. Here is my code :</p>
  
  <pre><code>public class MainActivity extends Activity implements OnClickListener {
  
  Button insert;
  EditText edt;
  TextView txt1, txt2, txt3, txt4, txt5;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      edt = (EditText) findViewById(R.id.search_word);
  
      txt1 = (TextView) findViewById(R.id.txt1);
      txt1.setOnClickListener(this);
  
      insert = (Button) findViewById(R.id.insert);
      insert.setOnClickListener(new OnClickListener() {
  
          public void onClick(View v) {
              if ((edt.getText().toString().equals(""))) {
                  Toast.makeText(
                          getBaseContext(),
                          "Whoa! You haven't entered anything in the search box.",
                          Toast.LENGTH_SHORT).show();
  
              } else {
                  SharedPreferences app_preferences = PreferenceManager
                          .getDefaultSharedPreferences(MainActivity.this);
                  SharedPreferences.Editor editor = app_preferences.edit();
                  String text = edt.getText().toString();
                  editor.putString("key", text);
                  editor.commit();
                  Toast.makeText(getBaseContext(), text, Toast.LENGTH_LONG)
                          .show();
              }
  
          }
      });
  }
  
  @Override
  protected void onStart() {
      // TODO Auto-generated method stub
      super.onStart();
  
      SharedPreferences app_preferences = PreferenceManager
              .getDefaultSharedPreferences(this);
      String text = app_preferences.getString("key", "null");
      txt1.setText(text);
  }
  
  public void onClick(View v) {
      String text = txt1.getText().toString();
      Toast.makeText(getBaseContext(), text, Toast.LENGTH_SHORT).show();
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Please help me in overcoming this problem.</p>