Save Array Within Activity
<p>I have an <code>Activity</code> which lets the user input names and the save them. Once the add <code>Button</code> is clicked the name gets added to the <code>Array</code> and also shown in a <code>ListView</code> with an option to remove a name.</p>

<p>My question is I am trying to get to the point where if the user leaves the <code>Activity</code> then comes back to the <code>Activity</code> the <code>Array</code> and <code>ListView</code> will have been saved so there is no need to input all the names again. At the moment once the <code>Activity</code> is left and then come back to the <code>Array</code> and <code>ListView</code> are empty.</p>

<p>As you can see at the bottom I have tried to use <code>onSaveInstanceState</code> and <code>onRestoreInstanceState</code> but can't get them to work can anyone expand on this code?</p>

<pre><code>ArrayList&lt;String&gt; playerList = new ArrayList&lt;String&gt;();
ListView employeeList;
ArrayAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.addremove);

final MyAdapter adapter = new MyAdapter(this, R.layout.listview_content, playerList);
ListView employeeList = (ListView) findViewById(R.id.namelistview);
employeeList.setAdapter(adapter);



Button confirm = (Button) findViewById(R.id.add);
confirm.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText playername = (EditText) findViewById(R.id.userinput);
playerList.add(playername.getText().toString());
adapter.notifyDataSetChanged();
playername.setText("");

}});

Button play = (Button) findViewById(R.id.playnow);
play.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent( demo.AddRemove.this, demo.PasswActivity.class);
intent.putStringArrayListExtra("KEY", playerList);
startActivity(intent);

}});
}
class MyAdapter extends ArrayAdapter&lt;String&gt;{
    private OnClickListener listener; 
    public MyAdapter(Context context, int textViewResourceId, ArrayList&lt;String&gt; objects) {
        super(context, textViewResourceId, objects);
        listener = new OnClickListener(){
            public void onClick(View v){
            playerList.remove(v.getTag());
            notifyDataSetChanged();

            };
            };
            }


    public View getView(int position, View convertView, ViewGroup parent) {
        if( convertView== null ) convertView = getLayoutInflater().inflate(R.layout.listview_content, null);

        TextView myTextView1 = (TextView)convertView.findViewById(R.id.playername);
        myTextView1.setText(getItem(position)); 
        Button remove = (Button)convertView.findViewById(R.id.remove);
        remove.setTag(getItem(position));
        remove.setOnClickListener(listener);
        return convertView;
    }
}

 @Override
 public void onSaveInstanceState(Bundle outState) {
   // Save UI state changes to the savedInstanceState.
   // This bundle will be passed to onCreate if the process is
   // killed and restarted.
     outState.putStringArrayList("Playlist", playerList );

    super.onSaveInstanceState(outState); }


    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
      super.onRestoreInstanceState(savedInstanceState);
      // Restore UI state from the savedInstanceState.
      // This bundle has also been passed to onCreate.
        playerList = savedInstanceState.getStringArrayList("Playlist");


    }
</code></pre>

<p>}</p>
