我正在尝试使用Couchbase开发Android应用程序。我有一个需要在活动中显示的对话。在我的onCreate方法中,我调用了setUpLiveQuery方法。如下:
private void setUpLiveQuery() {
final ProgressDialog progressDialog = showLoadingSpinner();
Query query = DBHelper.database.getView("chatDetailsView").createQuery();
query.setStartKey("chat_message_user_" + LoginUserHelper.userdata() + "_user_" + contactNumber + "\u02ad");
query.setEndKey("chat_message_user_" + LoginUserHelper.userdata() + "_user_" + contactNumber);
query.setDescending(true);
Log.v("start of method setupLiveQuery","");
LiveQuery liveQuery = query.toLiveQuery();
this.liveQuery = liveQuery;
liveQuery.addChangeListener(new LiveQuery.ChangeListener() {
@Override
public void changed(final LiveQuery.ChangeEvent event) {
Log.v("Inside method changed","");
runOnUiThread(new Runnable() {
public void run() {
// Iterating through the data fetched goes here
}
});
}
});
this.liveQuery.start();
现在注意setUpLiveQuery()中的日志并更改()当我运行时,几乎一分钟后调用changed()方法。请查看以下日志:
12-08 17:28:48.239 1977-1977 / com.chromosis.wishhapp.wishhapp V /方法setupLiveQuery的开始: 12-08 17:29:48.871 1977-2005 / com.chromosis.wishhapp.wishhapp V / Inside方法改变了:
之后的执行似乎更快,但对change()方法的回调需要很长时间。
请建议我是否正确处理liveQuery。