title: Xamarin Android lost data after re-opening app
body: <p>I have created an application that has save / load functions (personal data etc.). When the application is running, saving and loading data works well. Unfortunately, after re-opening the application stored data disappear and when I try to open files, i have a null reference exception. In settings (tools->option->xamarin) I checked "Preserve application data/cache on device between deploys". Below are my I/O functions:</p>
  
  <pre><code>public void SerializeObject(T obj)
      {            
          string jsonData = JsonConvert.SerializeObject(obj);
          JsonSerializer serializer = new JsonSerializer();
          serializer.NullValueHandling = NullValueHandling.Ignore;
          var documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
          var filePath = Path.Combine(documentsPath, "data.txt");
          System.IO.File.WriteAllText(filePath, jsonData);
      }
      public T DeSerializeObject()
      {
          var documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
          var filePath = Path.Combine(documentsPath, "data.txt");
          string text = System.IO.File.ReadAllText(filePath);
          T obj = JsonConvert.DeserializeObject&lt;T&gt;(text);
          return obj;
      }
  </code></pre>
  
  <p><strong>edit:</strong> Below is Button.click functions which save data. </p>
  
  <pre><code> private void saveButtonClick(object sender, EventArgs e)
      {            
          _data.x = this.x;
          _data.y = this.y;
          _data.z = this.z;
          IOoperation&lt;Data&gt; save = new IOoperation&lt;Data&gt;();
          save.SerializeObject(_data);
          TextView _current = FindViewById&lt;TextView&gt;(Resource.Id.currentPositionTextView);
          _current.Text = string.Format("Saved position: {0}, {1}, {2}", _data.x, _data.y, _data.z);
      }
  
      private void loadButtonClick(object sender, EventArgs e)
      {
          IOoperation&lt;Data&gt; load = new IOoperation&lt;Data&gt;();            
          Data obj = load.DeSerializeObject();
  
          TextView _current = FindViewById&lt;TextView&gt;(Resource.Id.currentPositionTextView);
          _current.Text = string.Format("Saved position: {0}, {1}, {2} - loaded", _data.x, _data.y, _data.z);
      }
  </code></pre>