title: How to maintaining listView (java/android)
body: <p>I have a listview in the SubActivity of my app.. but when I go from the subActivity to the main Activity and i try to return to the subActivity, the item of the listView disappear.. how to fix this problem?
  also if I close my app and i restart it, my listview is empty... why?</p>
  
  <p>my MainActivity:</p>
  
  <pre><code>final ArrayList&lt;String&gt; listCron = new ArrayList&lt;String&gt;();
  ....
  @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();
  
      switch(id) {
          case R.id.history:
              Intent history = new Intent(getApplicationContext(), HistoryClass.class);
  
              history.putStringArrayListExtra("history", listCron);
              startActivity(history);
              break;
  
          default:
              return true;
      }
      return super.onOptionsItemSelected(item);
  }
  </code></pre>
  
  <p>my SubActivity:</p>
  
  <pre><code> @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.history_main);
  
      Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(mToolbar);
      getSupportActionBar().setHomeButtonEnabled(true);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  
  
      Intent i = getIntent();
      ArrayList&lt;String&gt; cronologia = i.getStringArrayListExtra("history");
  
      ListView lv = (ListView) findViewById(R.id.viewCron);
      if (cronologia.isEmpty()) {
          cronologia.add("No operations");
      }
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, R.layout.listview_layout, cronologia);
      lv.setAdapter(adapter);
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>my manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.VIBRATE"/&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme"&gt;
      &lt;activity
          android:name=".MainActivity"
          android:label="@string/app_name"
          android:windowSoftInputMode="stateAlwaysHidden"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity android:name=".HistoryClass"
          android:label="@string/history"&gt;
      &lt;meta-data
          android:name="android.support.PARENT_ACTIVITY"
          android:value=".MainActivity"/&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>