title: Realm won't save the variable/object once the application is closed. How do I fix this?
body: <p>I already have one Realm object working perfectly fine with the Realm. But, my Points object is not saving. When running the app on the Android emulator, clearing it from recents clears the points variable of the Points class. There is only one instance of Points throughout the entire application. I'll insert code of how I'm using Points below. I've also observed the variable updating in the Realm using Stetho with chrome, so it's definitely saving to the database. </p>
  
  <p>MyApplication class where I initially create the object in Realm:</p>
  
  <pre><code>public class MyApplication extends Application {
  
  static Realm realm;
  
  @Override
  public void onCreate() {
      super.onCreate();
  
      Realm.init(this);
  
      RealmConfiguration config = new RealmConfiguration.Builder()
              .name("chargerpoints.realm")
              .schemaVersion(1)
              .build();
  
      realm = Realm.getInstance(config);
      realm = Realm.getDefaultInstance();
  
      Points pts = realm.where(Points.class).findFirst();
  
      if(pts == null) {
          Points myPoints = new Points();
          myPoints.setId(1);
          myPoints.setPts(0);
          realm.beginTransaction();
          realm.copyToRealmOrUpdate(myPoints);
          realm.commitTransaction();
      }
  </code></pre>
  
  <p>MainActivity where I increment the points integer variable of myPoints object using a timer: </p>
  
  <pre><code>static int points;
  
  Points myPoints;
  
  Context context = this;
  
  Calendar c = Calendar.getInstance();
  int hours = c.get(Calendar.HOUR_OF_DAY);
  
  private Timer timer;
  private TimerTask timerTask = new TimerTask() {
      @Override
      public void run() {
          if(hours &gt; 7 &amp;&amp; hours &lt; 15){
              KeyguardManager myKM = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
              if (myKM.inKeyguardRestrictedInputMode()) {
                  points++;
              } else {
                  realm = Realm.getDefaultInstance();
                  myPoints = realm.where(Points.class).findFirst();
                  realm.beginTransaction();
                  myPoints.setPts(points);
                  realm.copyToRealmOrUpdate(myPoints);
                  realm.commitTransaction();
              }
              displayPoints();
          }
      }
  };
  </code></pre>
  
  <p>I have basically tried every possible combination and haven't come close to data persistency with the Points class so far. I already have another object working fine with Realm, so its confusing as to why this one wouldn't work. Thanks for the help!</p>