title: How to add item to string array in activity 'a' by click on the button in activity 'b' and save the items after exit from app?
body: <p>I asked this question yesterday:</p>
  
  <p>I have a problem. I want to add some items to my list view which is in activity 'b' by click on the button or other view in activity 'a'. For example:</p>
  
  <p>My Activity 'a' :</p>
  
  <pre><code>b.setOnClickListener(new onClickListener() {
      @Override
      public void onClick(view v) {
          // add item to myarray which there in activity 'b'
          myArray.add("");
      }
  });
  </code></pre>
  
  <p>My Activity 'b' :</p>
  
  <pre><code>ArrayList&lt;String&gt; myArray;
  </code></pre>
  
  <p>Hope to get my purpose. Thank-you.</p>
  
  <p>Then I get this answer:</p>
  
  <p>You can create a third object ( A public class where you put the ArrayList ) and access it every time you need its values : Update it from first activity and get values from second activity.</p>
  
  <p>Activity 1:</p>
  
  <pre><code>b.setOnClickListener(new onClickListener() {
      @Override
      public void onClick(view v) {
          Utilities.addValue("String");
      }
  });
  </code></pre>
  
  <p>Activity 2:</p>
  
  <pre><code>ArrayList&lt;String&gt; myArray = Utilities.getArrayList();
  </code></pre>
  
  <p>Utility Class:</p>
  
  <pre><code>public static class Utilities {
      static ArrayList&lt;String&gt; mArrayList;
  
      public static void addValue(String a) {
          if (null == mArrayList) {
              mArrayList = new ArrayList&lt;&gt;();
          }
          mArrayList.add(a);
      }
  
      public static ArrayList&lt;String&gt; getArrayList() {
          return mArrayList;
      }
  }
  </code></pre>
  
  <p>But I have a new problem. When I click on the button, item add to the array string and show in list view. But when I exit from app and comeback later to the app, Activity 'b' which there is the list view in it, crashed. What the problem? How to save added items? Thankyou.</p>