背景
我正在使用parse.com作为我的后端开发Android的群发消息应用程序。
工作:
我有一个ParseQueryAdapter,它使用以下命令从本地数据存储区查询ChatGroup:
public ChatGroupAdapter(final Context context) {
super(context, new ParseQueryAdapter.QueryFactory<ChatGroup>() {
public ParseQuery<ChatGroup> create() {
ParseQuery<ChatGroup> chatGroupQuery = ParseQuery.getQuery(ChatGroup.class);
chatGroupQuery.fromLocalDatastore();
Log.d(ChatGroup.class.getName(), "Constructor query: " +
chatGroupQuery + " made");
//noinspection unchecked
return chatGroupQuery;
}
});
}
包含它的片段通过添加ParseQueryAdapter.OnQueryLoadListener
来侦听它。如果ParseQueryAdapter
无法从本地数据存储中检索ChatGroup
,则会从解析中检索它,将其固定,然后触发ParseQueryAdapter
以使用以下命令从本地数据存储重试加载:{{1 }}。这是我的片段中的代码片段:
.loadObjects();
结果:
这是一个简化的执行日志:
@Override
public void onLoaded(List<ChatGroup> groups, Exception e) {
l.d("onLoaded called");
if (e != null) {
e.printStackTrace();
updateLocalDatastore();
} else if (groups == null) {
l.w("Received null group list.");
updateLocalDatastore();
} else if (groups.size() == 0) {
l.w("Received group list of size zero.");
updateLocalDatastore();
} else {
l.d("Chat groups loaded successfully");
}
}
private void updateLocalDatastore() {
final ParseQuery<ChatGroup> groupQuery = ParseQuery.getQuery(ChatGroup.class);
groupQuery.findInBackground(new FindCallback<ChatGroup>() {
@Override
public void done(final List<ChatGroup> chatGroupList, ParseException e) {
if (e != null) {
e.printStackTrace();
} else {
if (chatGroupList != null) {
ParseObject.pinAllInBackground(chatGroupList, new SaveCallback() {
@Override
public void done(ParseException e) {
if (e != null) {
e.printStackTrace();
} else {
l.d("Successfully pinned: " + chatGroupList.size() +
" groups to local datastore. Reloading adapter");
groupAdapter.loadObjects();
}
}
});
} else {
l.e("Received null group list from cloud! " +
"Local datastore update failed!");
}
}
}
});
}
我很明显ChatFragment: onCreate
ChatFragment﹕ Initializing chat groups
ChatFragment﹕ Loading chat groups
ChatFragment: onStart
ChatFragment: onResume
ChatFragment﹕ onLoaded called
ChatFragment﹕ Received group list of size zero.
ChatFragment﹕ Successfully pinned: 3 groups to local datastore. Reloading adapter
ChatFragment﹕ Loading chat groups
ChatFragment﹕ onLoaded called
ChatFragment﹕ Received group list of size zero.
ChatFragment﹕ Successfully pinned: 3 groups to local datastore. Reloading adapter
ChatFragment﹕ Loading chat groups
ChatFragment﹕ onLoaded called
ChatFragment﹕ Received group list of size zero.
ChatFragment﹕ Successfully pinned: 3 groups to local datastore. Reloading adapter
ChatFragment﹕ Loading chat groups
ChatFragment﹕ onLoaded called
ChatFragment﹕ Received group list of size zero.
应该首次检索0列表,触发ParseQueryAdapter
从解析中提取3 updateLocalDatastore()
,然后将它们固定从本地数据存储区收到3。 但是,如日志所示,即使成功固定后,它仍会从本地数据存储中找到0 ChatGroup
个!
项目设置似乎很好:
ChatGroup
我做错了什么?!我错过了什么吗?
我用Parse.enableLocalDatastore(this);
Parse.initialize(this, AppProps.properties.appId, AppProps.properties.clientKey);
ParseUser.enableRevocableSessionInBackground();
Parse.setLogLevel(Parse.LOG_LEVEL_DEBUG);
ParseObject.registerSubclass(ChatGroup.class);
实现了完全相同的逻辑,它运行得很完美!使用ParseUser
执行相同操作似乎有问题:
GroupChat
有人说它是在本地数据存储区中具有关系的解析bug。但我甚至没有使用关系。即使来自本地数据存储区的简单查询也不起作用。
答案 0 :(得分:0)
虽然我无法解决问题,但我发现了问题所在。该问题与Android的Parse SDK的基本错误有关:ParseQuery gives 0 objects when querying from local datastore even after successfully pinning