我想在執行完成後關閉我的領域實例executeTransactionAsync
。原因是我的應用程序主線程凍結,我認爲它的原因是後臺領域實例在執行完成後沒有被關閉。看到我的代碼如下:執行完畢後關閉領域實例
realm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm realm) {
// Execute realm code
realm.copyToRealmOrUpdate(myData);
// Can I close the realm instance here without getting an
// error? realm.close(); causes an error.
}
}, new Realm.Transaction.OnSuccess() {
@Override
public void onSuccess() {
Log.i("CB", "success");
// looks like I cannot access the execute Realm
// instance here.
// Closing realm.getDefaultInstance does not change my issue
}
}, new Realm.Transaction.OnError() {
@Override
public void onError(Throwable error) {
Log.i("CB", "error - " + error.getMessage());
}
});
}
請參閱我的意見。我的應用程序屏幕變成黑色。執行成功完成並調用onSuccess()
,但我無法訪問execute
領域實例從此處關閉它。
對於我可以嘗試的方法,您有什麼建議嗎?難道我做錯了什麼?
預先感謝您。
編輯
07-19 11:43:42.379 8146-8146/com.shortterminsurance.shortterm I/CB: success
07-19 11:43:43.258 8146-8152/com.shortterminsurance.shortterm W/art: Suspending all threads took: 33.234ms
07-19 11:43:43.266 8146-8156/com.shortterminsurance.shortterm I/art: Background partial concurrent mark sweep GC freed 476307(17MB) AllocSpace objects, 512(10MB) LOS objects, 40% free, 33MB/55MB, paused 7.261ms total 163.497ms
07-19 11:43:44.131 8146-8156/com.shortterminsurance.shortterm I/art: Background sticky concurrent mark sweep GC freed 408160(9MB) AllocSpace objects, 459(15MB) LOS objects, 35% free, 35MB/55MB, paused 10.287ms total 147.823ms
07-19 11:43:44.834 8146-8152/com.shortterminsurance.shortterm W/art: Suspending all threads took: 103.676ms
07-19 11:43:44.848 8146-8156/com.shortterminsurance.shortterm W/art: Suspending all threads took: 13.424ms
這是我的logcat我的onSuccess被調用後。我認爲在execute
的領域的背景實例保持運行的原因:(。
等待您要關閉哪個領域實例?你用'background instance'指的是什麼? –
@TimCastelijns我想在'execute'中關閉領域實例。將更快地編輯我的問題 – Lunchbox
你的意思是這裏傳遞的實例public void execute(Realm realm){'? –