title: How do you check if a realm instance has been closed already?
body: <p>I'm using Realm for Android to store some data. When the user presses the log out button, I'd like to clear my entire Realm database. To do that, I have the following snippet of code:</p>
  
  <pre><code>realm.close();
  realm.deleteRealmFile(this);
  goToLoginActivity();
  </code></pre>
  
  <p>The issue now is in my onResume function. I'm getting the following exception: </p>
  
  <p><strong>Caused by: java.lang.IllegalStateException: This Realm instance has already been closed, making it unusable.</strong></p>
  
  <p>My onResume code is as follows:</p>
  
  <pre><code>@Override
  protected void onResume() {
      super.onResume();
  
      // I'm trying to check if the realm is closed; this does not work
      if (realm == null) {
          realm = Realm.getInstance(this);
      }
  
      // Do query using realm
  }
  </code></pre>
  
  <p>How can I check to see if a realm object has been closed already? Alternatively, is there a better way to clear the database than deleting the realm file?</p>
  
  <p>--</p>
  
  <p>Edit: Just saw <a href="https://stackoverflow.com/questions/26185679/how-can-i-easily-delete-all-objects-in-a-realm">How can I easily delete all objects in a Realm</a> for iOS. Any word on when the deleteAllObjects API will be available for Android? At the time of writing, Android is at version 0.80.0 and the API is available in iOS in 0.87.0.</p>