title: Save SharePreference string to a ListView
body: <p>I have two activities. Let's say "A" and "B", Activity "A" has a button called "Get" which generates a new string after each click and displays them one at a time.  And the activity "A" also has a button "send" which will send the generated strings to another activity "B". When the activity "B" receives the data, it has to populate the data into a ListView. </p>
  
  <p>Here's the simple step by step machine steps:</p>
  
  <pre><code>In Activity "A"
  1 - Generate 1 string by pressing the generate button
  2 - text will be displayed in textView
  3 - "send" button will send the text from textView to another activity "B" ( I'm using sharedPreference)
  
  In Activity "B"
  4 - receive the data sent by Activity "A" ( I'm using sharedPreference)
  5 - populate string into a listview
  6 - go to step 1 again.  
  </code></pre>
  
  <p>My trouble is that whenever I click the send button, it will send the string to Activity "B" but when I do the same task again, it will only populate the last generated string. In other words, my code only populates one string.</p>
  
  <p>I have tried following code so far, any help would be appreciated.</p>
  
  <pre><code>@Override
      public void onClick(View view) {
  
  
          switch(view.getId()) {
              case R.id.generateButton:
                  generateString();
                  break;
  
              case R.id.send:
  
                  //displayText is a textView
                  String text = displayText.getText().toString(); 
  
                  // data sharing using sharedPref
                  SharedPreferences.Editor editor = getApplicationContext().getSharedPreferences("lado", MODE_PRIVATE).edit();
                  editor.putString("mug",text);
                  editor.apply();
                  break;
  
  
          }
  
  ---------
  </code></pre>
  
  <p>Activity B</p>
  
  <pre><code>ListView textList = (ListView) findViewById(R.id.list);
  
          SharedPreferences prefs = getSharedPreferences("lado", MODE_PRIVATE);
          final String text = prefs.getString("mug", "No name defined");
  
         String[] list = new String[]{name};
  
  
          // Create a List from String Array elements
          final List&lt;String&gt; fav_list = new ArrayList&lt;&gt;(Arrays.asList(list));
  
  
  
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;&gt;(this,
                  android.R.layout.simple_list_item_1, android.R.id.text1,list);
  
          // Assign adapter to ListView
          textList.setAdapter(adapter);
  </code></pre>