title: ArrayList / ArrayAdapter .add() function overwriting last element instead of adding to end of array
body: <p>I'm working on a school assignment which is to create a Bookmarking app with 2 activites, a ListActivity called BookNote and an activity called ManageActivity.</p>
  
  <p>All typing must be done in ManageActivity and passed back to BookNote for list changes, reading, and writing data.</p>
  
  <p>My problem is when I call the function "addBookmark" in BookNote activity. What I want to happen is for a new list item to be added at the end of the list with the bookmark objects info in it. </p>
  
  <p>What is happening is that whatever item is at the end of the list is simply overwritten instead of a new item being created.</p>
  
  <p>My code is below with comments stating my intentions of each function.</p>
  
  <p><strong>BookNote activity</strong></p>
  
  <pre><code>public class BookNote extends ListActivity{
      private ArrayAdapter&lt;Bookmark&gt; adapter;
      private final String FILENAME = "bookmarks.txt";
      public String title = "EMPTY", url = "EMPTY", note = "EMPTY";
      public String bookmarkClicked ="";
      public int listViewID = 0;
      public boolean intentListener = false;
      public int intentReturnCounter = 0;
      public boolean addBookmarkClicked = false;
      public ArrayList&lt;Bookmark&gt; bookmarkList;
  
  
      /*When activity is called, list is populated by readData(), addBookmarkClicked is reset to false, intentLister is changed to true if returning from ManageActivity,
        if intentListener is true, addBookmarkClicked will be changed to true if AddBookmark is clicked from the BookNote menubar, a bookmark object will be created with information
         passed back from ManageActivity, and if addBookmarkClicked is true, the bookmark object will be added to the end of the list, otherwise it will be inserted in the same
         list element from which was chosen to edit.*/
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
  
          bookmarkList = readData();
          adapter = new ArrayAdapter&lt;Bookmark&gt;(this, android.R.layout.simple_list_item_1, bookmarkList);
          setListAdapter(adapter);
  
          addBookmarkClicked = false;
          intentListener = false;
  
  
  
              intentListener = getIntent().getBooleanExtra("listen", false);
  
              if (intentListener == true) {
                  addBookmarkClicked = getIntent().getExtras().getBoolean("addBookmarkClicked", false);
                  title = getIntent().getExtras().getString("title");
                  url = getIntent().getExtras().getString("url");
                  note = getIntent().getExtras().getString("note");
                  listViewID = getIntent().getExtras().getInt("listViewID");
                  Bookmark bookmark = new Bookmark(title, url, note);
                  Toast.makeText(getApplicationContext(), "Intent return: True", Toast.LENGTH_SHORT).show();
                  intentListener = false;
  
                  if (addBookmarkClicked == true) {
                      addBookmark(bookmark);
                      Toast.makeText(getApplicationContext(), "Bookmark Added", Toast.LENGTH_SHORT).show();
                      addBookmarkClicked = false;
                  } else {
                      insertBookmark(bookmark, listViewID);
                      Toast.makeText(getApplicationContext(), "Bookmark Edited", Toast.LENGTH_SHORT).show();
                  }
                  //writeData();
          }
      }
  
  
  
      //reads data when app runs and fills arrayadapter and list with items saved to bookmarks.txt
      private ArrayList&lt;Bookmark&gt; readData(){
          ArrayList&lt;Bookmark&gt; bookmarks = new ArrayList&lt;&gt;();
  
          try {
              FileInputStream fis = openFileInput(FILENAME);
              Scanner scanner = new Scanner(fis);
              if (scanner.hasNext()){
                  String titleScan = scanner.nextLine();
                  String urlScan = scanner.nextLine();
                  String noteScan = scanner.nextLine();
                  Bookmark bookmark = new Bookmark(titleScan, urlScan, noteScan);
                  bookmarks.add(bookmark);
              }else{
                  Bookmark bookmark = new Bookmark("Example Title", "Example URL", "Example Note");
                  bookmarks.add(bookmark);
              }
              scanner.close();
          } catch (FileNotFoundException e) {
          }
          return bookmarks;
      }
  
      private void writeData(){
          try {
              FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
              OutputStreamWriter osw = new OutputStreamWriter(fos);
              BufferedWriter bw = new BufferedWriter(osw);
              PrintWriter pw = new PrintWriter(bw);
  
              for(int i = 0; i &lt; adapter.getCount(); i++){
                  Bookmark bookmark = adapter.getItem(i);
                  pw.println(bookmark.getTitle() + "\n" + bookmark.getUrl() + "\n" + bookmark.getNote());
              }
              pw.close();
          } catch (FileNotFoundException e) {
              Log.e("Write ERR", "Cannot save: " + e.getMessage());
              e.printStackTrace();
              Toast.makeText(BookNote.this, "Error saving", Toast.LENGTH_SHORT).show();
          }
      }
  
      //If addBookmark menu item is clicked, this will be called to add a bookmark to the end of the ArrayAdapter.
      private void addBookmark(Bookmark bookmark){
          adapter.add(bookmark);
          writeData();
      }
  
  
      //Calls ManageActivity and reports information about app.
      public void gotoManageActivity(boolean addBookmarkClicked){
          Intent manageIntent = new Intent(this, ManageActivity.class);
          Bundle extras = new Bundle();
          extras.putString("bookmark", bookmarkClicked);
          extras.putBoolean("addBookmarkClicked", addBookmarkClicked);
          extras.putInt("listViewID", listViewID);
          manageIntent.putExtras(extras);
          startActivity(manageIntent);
      }
  
  
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_add) {
              addBookmarkClicked = true;
              gotoManageActivity(addBookmarkClicked);
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  }
  </code></pre>
  
  <p><strong>ManageActivity</strong></p>
  
  <pre><code>public class ManageActivity extends AppCompatActivity {
  
      private String title = "EMPTY", url = "EMPTY", note = "EMPTY";
      private boolean listener = true;
      private boolean addBookmarkClicked = false;
  
  
  
  /* When activity starts, check for addBookmarkClicked status, create book */
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.manage_layout);
  
          addBookmarkClicked = getIntent().getExtras().getBoolean("addBookmarkClicked", false);
  
          String bookmarkString = "";
          bookmarkString = getIntent().getExtras().getString("bookmark");
          if(bookmarkString != null &amp;&amp; bookmarkString.length() &gt; 0) {
              if (bookmarkString.length() != 0) {
                  String[] stringArray = bookmarkString.split("\\n");
                  title = stringArray[0];
                  url = stringArray[1];
                  note = stringArray[2];
                  updateTextViews();
              }
          }
          else { updateTextViews();
          }
      }
  
      @Override
      public void onBackPressed(){
          Intent bookNoteIntent = new Intent(this, BookNote.class);
          Bundle extras = new Bundle();
  
          if(title.length() == 0 || title == null){title= "Empty";}
          if(url.length() == 0 || url == null){ url = "Empty";}
          if(note.length() == 0 || url == null) { note = "Empty";}
  
          extras.putString("title", title);
          extras.putString("url", url);
          extras.putString("note", note);
          extras.putBoolean("listen", listener);
          extras.putBoolean("addBookmarkClicked", addBookmarkClicked);
          bookNoteIntent.putExtras(extras);
          startActivity(bookNoteIntent);
      }
  </code></pre>