所以,我已經使用Realm一段時間了。目前,我有一項任務是與其他應用程序共享登錄數據。與內容提供商的領域
由於登錄數據使用境界存儲。我選擇使用Content Provider。
我發現了一個例子:https://speakerdeck.com/androhi/realm-with-contentprovider
不幸的是,我無法使它工作。這是我的內容提供商應用程式
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<LoginResultData> 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;
}
應用B(這需要獲得登錄數據)得到了掛在我
getContentResolver.query(uri, null, null, null, null);
我不知道爲什麼,但它的工作以及當我使用SQlite時。所以我假設Realm與Content Provider smh不能很好地協作。真的嗎?
如果不是,請告訴我一個樣品,使用內容提供商與境界。
謝謝!
你設置'androi d:multiprocess'爲true? – Dalinaum