title: How do I save data permanently so I can access it later in Android?
body: <p>Whenever I press the back button my app doesn't call <code>onSaveInstanceState()</code> and I can't save data. I'm trying to make a scheduler app and I need to save schedules already set even after I press the back button. I want to dynamically edit a ListView by adding new data from the source file to a stringArray. The problem I'm having is that the file schedules.txt is not saving. Whenever the program opens a new activity the file is now blank.</p>
  
  <p>This is the code I have so far:</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.activity_schedules);
      ListView listview = (ListView) findViewById(R.id.scheduleListView);
      adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_list_item_1, schedulesList); 
      listview.setAdapter(adapter);
      Log.v("myapp", "currentlist of files associated with this program are: " + fileList());
  
      try {
  
          FileOutputStream fout = openFileOutput("schedules.txt", MODE_PRIVATE);
          Log.v("myapp", "FileOutputStream ran");
  
      } catch (FileNotFoundException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
      }
  
  try {
         Log.v("myapp", "first get old schedules call");
         getOldSchedules();
  } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
  
  
  public void editFile(String format) throws IOException {
  
      Log.v("myapp", "editFile ran");
      FileOutputStream fout = openFileOutput("schedules.txt", MODE_PRIVATE);
      OutputStreamWriter writer = new OutputStreamWriter(fout);
  
      writer.write("hello alex");
      writer.flush();
      writer.close();
      Log.v("myapp", "secondary getoldschedules call");
      getOldSchedules();
  }
  
  public void getOldSchedules() throws IOException{
  
      FileInputStream fis = openFileInput("schedules.txt");
      InputStreamReader reader = new InputStreamReader(fis);
  
      char[] inputbuffer = new char[32];
      reader.read(inputbuffer);
      String data = new String(inputbuffer);
      Log.v("myapp", "data in file reads: " + data);
  
      reader.close();
  
  
  }
  </code></pre>