title: Realm with Content Provider
body: <p>So, I've been used Realm for a while. For now, I have a task to share the login data with my other apps.</p>
  
  <p>Since the login data is stored using Realm. I choose to use Content Provider.</p>
  
  <p>I found an example: <a href="https://speakerdeck.com/androhi/realm-with-contentprovider" rel="nofollow noreferrer">https://speakerdeck.com/androhi/realm-with-contentprovider</a></p>
  
  <p>Unfortunately, I was unable to make it work. This is my Content Provider in <strong>app A</strong></p>
  
  <pre><code>static final String[] sColumns = new String[]{
          "LoginResultData"
  };
  
  public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection,
                      @Nullable String[] selectionArgs, @Nullable String sortOrder) {
  
      Realm mRealm = Realm.getDefaultInstance();
  
      RealmQuery&lt;LoginResultData&gt; query = mRealm.where(LoginResultData.class);
      LoginResultData result = query.findFirst();
  
      String json = new Gson().toJson(result);
  
      MatrixCursor matrixCursor = new MatrixCursor(sColumns);
      Object[] rowData = new Object[]{json};
      matrixCursor.addRow(rowData);
  
      return matrixCursor;
  }
  </code></pre>
  
  <p><strong>App B</strong> (which need to get the login data) got hang when I</p>
  
  <pre><code>getContentResolver.query(uri, null, null, null, null);
  </code></pre>
  
  <p>I don't know why but it worked well when I use SQlite. So I'm assuming that Realm doesn't work well with Content Provider smh. Is that true?</p>
  
  <p>If not, please show me a sample to using Content Provider with Realm. </p>
  
  <p>Thanks!</p>