title: Android studio pass ListView to another activity
body: <p>I am trying to pass an array list to another activity but it seems that is not enough. I searched all day to pass the array list with "intent" but with no success. I wrote a code for learning purposes. How to pass the data and show the Arraylist in a second activity?</p>
  
  <p>The action button is btn_save. If you want further details let me know.</p>
  
  <p>The code is in </p>
  
  <p>MainActivity  (first activity):</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      ArrayList&lt;String&gt; addArray = new ArrayList&lt;&gt;();
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          final EditText editTextOne = (EditText) findViewById(R.id.editTextOne);
          final EditText editTextTwo = (EditText) findViewById(R.id.editTextTwo);
          Button btn_showText = (Button) findViewById(R.id.buttonShow);
          final TextView textView = (TextView) findViewById(R.id.textResults);
          Button btn_refresh = (Button) findViewById(R.id.btn_refresh);
          Button btn_close = (Button) findViewById(R.id.btn_close);
          Button btn_save = (Button) findViewById(R.id.btn_save);
          final ListView showMe = (ListView) findViewById(R.id.list_items);
  
          btn_showText.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  String text = editTextOne.getText().toString();
                  String textTwo = editTextTwo.getText().toString();
  
                  if (text.length() == 0 || textTwo.length() == 0){
                      textView.setText("You must enter Name &amp; Surname");
                  }else {
                      textView.setText(Html.fromHtml(
  
                              "&lt;font color=\"red\"&gt;"+ text +  "&lt;/font&gt; " +
                                      "&lt;font color=\"blue\"&gt;&lt;b&gt;" + textTwo + " &lt;/b&gt;&lt;/font&gt;"));
                  }
              }
          });
          btn_refresh.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  finish();
                  startActivity(getIntent());
              }
          });
          btn_close.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  finish();
                  System.exit(0);
              }
          });
  
          btn_save.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  //              Context context = getApplicationContext();
  //              CharSequence mytext = "Hahahaha";
  //              int duration = Toast.LENGTH_SHORT;
  //              Toast toast = Toast.makeText(context,mytext,duration);
  //              toast.show();
                  String text = editTextOne.getText().toString();
                  String textTwo = editTextTwo.getText().toString();
                  String getInput = text + textTwo;
                  if (addArray.contains(getInput)){
                      Toast.makeText(getBaseContext(), "Item already Added!", Toast.LENGTH_LONG).show();
                  }
                  else if (getInput == null || getInput.trim().equals("")){
                      Toast.makeText(getBaseContext(), "Input field is empty", Toast.LENGTH_LONG).show();
                  }
                  else{
                      addArray.add(getInput);
                      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;&gt;(MainActivity.this, android.R.layout.simple_list_item_1, addArray);
                      showMe.setAdapter(adapter);
                      Intent intent = new Intent(MainActivity.this, ListOfNames.class);
  
                      ((EditText)findViewById(R.id.editTextOne)).setText(" ");
                      ((EditText)findViewById(R.id.editTextTwo)).setText(" ");
                  }
              }
          });
  
  
      }
  
      public void onButtonClick(View v){
  
          if (v.getId() == R.id.btn_list){
              Intent i = new Intent(MainActivity.this, ListOfNames.class);
              startActivity(i);
          }
  
      }
  
  }
  </code></pre>
  
  <p>ListOfNames second activity: (almost empty)</p>
  
  <pre><code>public class ListOfNames extends Activity {
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.list_screen);
  
      }
  }
  </code></pre>