@Override
 public void onPause() {
   super.onPause();
   // When the app is paused, stop listening for changes and close the datastore.
   if (mDatastore != null) {
     mDatastore.removeSyncStatusListener(mDatastoreListener);
     mDatastore.close();
     mDatastore = null;
   }
 }
 @Override
 public void onDatastoreStatusChange(DbxDatastore dbxDatastore) {
   if (dbxDatastore.getSyncStatus().hasIncoming) {
     try {
       dbxDatastore.sync();
     } catch (DbxException e) {
       e.printStackTrace();
     }
     updateLevel();
   }
 }
 @Override
 public void onResume() {
   super.onResume();
   // When the app resumes, open the datastore and start listening for changes.
   if (mDatastore == null && mAccountManager.hasLinkedAccount()) {
     try {
       mDatastore = DbxDatastore.openDefault(mAccountManager.getLinkedAccount());
       DbxTable table = mDatastore.getTable("state");
       table.setResolutionRule("level", DbxTable.ResolutionRule.MAX);
       mDatastore.addSyncStatusListener(mDatastoreListener);
       updateLevel();
     } catch (DbxException e) {
       e.printStackTrace();
     }
   }
 }
 DbxRecord getRecord() {
   DbxRecord record = null;
   try {
     // We use getOrInsert to initialize the record to level 0.
     record =
         mDatastore
             .getTable("state")
             .getOrInsert("current_level", new DbxFields().set("level", 0.0));
   } catch (DbxException e) {
     e.printStackTrace();
   }
   return record;
 }