title: Passing data from other activity using intents and displaying in listview
body: <p>i  am new to android, i have created two activities where main activity consist one button to go to secondActivity in second activity where the user inputs name and the data is taken back to main activity using intents.The problem i am facing is i want to display the data in listview</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends Activity {
  Button addcontact;
  ListView listview;
  //TextView name;
  ArrayAdapter&lt;String&gt; listAdapter;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      listview = (ListView) findViewById(R.id.listView1);
      TextView name = (TextView) findViewById(R.id.txtname);
      addcontact = (Button) findViewById(R.id.addbtn);
  
      addcontact.setOnClickListener(new View.OnClickListener() {
          @Override
              public void onClick(View v) {
              Intent i = new Intent(MainActivity.this, SecondActivity.class);
              startActivityForResult(i, 1);
              savedata();
          }
      });
  }
  
  private void savedata() {
      Intent intent = getIntent();
      String fName = intent.getStringExtra("fname");
      List&lt;String&gt; ListElements = new ArrayList&lt;String&gt;(Arrays.asList(fName));
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;       (MainActivity.this,android.R.layout.simple_list_item_1, ListElements);     
      listview.setAdapter(adapter);
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>SecondActivity.java</strong></p>
  
  <p>public class SecondActivity extends Activity {</p>
  
  <pre><code>EditText edname;
  Button addbtn;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_second);
  
      edname =(EditText) findViewById(R.id.edname);
      addbtn = (Button) findViewById(R.id.savebtn);
  
      addbtn.setOnClickListener(new View.OnClickListener() {
       @Override
      public void onClick(View v) {
      Intent intent = new Intent(SecondActivity.this,   MainActivity.class);
      intent.putExtra("fname", edname.getText().toString());
      startActivity(intent);
      }
    });
  </code></pre>
  
  <p>}
  }</p>