简体   繁体   English

即使成功固定后,使用ParseQueryAdapter查询本地数据存储区也会得到0个结果

[英]Querying local datastore in using ParseQueryAdapter gives 0 results even after successfully pinning

Background: 背景:
I am working on a group messaging app for Android using parse.com as my backend. 我正在使用parse.com作为后端在Android上使用群发消息应用程序。

Working: 工作方式:

  1. I Have a ParseQueryAdapter which queries for ChatGroups from the local datastore using: 我有一个ParseQueryAdapter,它使用以下命令从本地数据存储区查询ChatGroups:

     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; } }); } 
  2. The fragment that contains it listens to it by adding a ParseQueryAdapter.OnQueryLoadListener . 包含它的片段通过添加ParseQueryAdapter.OnQueryLoadListener来监听它。 If the ParseQueryAdapter cannot retrieve the ChatGroup s from the local datastore, it retrieves it from parse, pins it and then triggeres the ParseQueryAdapter to retry loading from the local datastore using: .loadObjects(); 如果ParseQueryAdapter无法从本地数据存储中检索ChatGroup ,则从解析中检索它,将其固定,然后触发ParseQueryAdapter使用以下.loadObjects();重试从本地数据存储中加载: .loadObjects(); . Here is a code snippet from my fragment: 这是我的片段中的代码片段:

     @Override public void onLoaded(List<ChatGroup> groups, Exception e) { ld("onLoaded called"); if (e != null) { e.printStackTrace(); updateLocalDatastore(); } else if (groups == null) { lw("Received null group list."); updateLocalDatastore(); } else if (groups.size() == 0) { lw("Received group list of size zero."); updateLocalDatastore(); } else { ld("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 { ld("Successfully pinned: " + chatGroupList.size() + " groups to local datastore. Reloading adapter"); groupAdapter.loadObjects(); } } }); } else { le("Received null group list from cloud! " + "Local datastore update failed!"); } } } }); } 

Result: 结果:
And here is a simplified log of the execution: 这是执行的简化日志:

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.

It seems obvious to me that the ParseQueryAdapter should retrieve a list of 0 the first time which triggers the updateLocalDatastore() which pulls 3 ChatGroup s from parse, pin them and then it should receive 3 from the local datastore. 对我来说似乎很明显, ParseQueryAdapter第一次应检索到0列表,这会触发updateLocalDatastore() ,它从解析中提取3个ChatGroup ,将其固定,然后应从本地数据存储中接收3个。 However as seen in the log, it continues to find 0 ChatGroup s from the local datastore even after pinning them successfully! 但是,从日志中可以看到,即使成功将其固定后,它仍会从本地数据存储中继续找到0个ChatGroup

The project setup seems fine: 项目设置似乎很好:

Parse.enableLocalDatastore(this);
Parse.initialize(this, AppProps.properties.appId, AppProps.properties.clientKey);
ParseUser.enableRevocableSessionInBackground();
Parse.setLogLevel(Parse.LOG_LEVEL_DEBUG);
ParseObject.registerSubclass(ChatGroup.class);

What am I doing wrong?! 我究竟做错了什么?! Am I missing something? 我想念什么吗?

I implemented the exact same logic with ParseUser and it worked flawlessly! 我使用ParseUser实施了完全相同的逻辑,并且完美无缺! There seems to be something wrong with doing the same with GroupChat : 使用GroupChat进行相同操作似乎有GroupChat

@ParseClassName("ChatGroup")
public class ChatGroup extends ParseObject {

Some say that it is a parse bug with relations in the local datastore. 有人说这是与本地数据存储区中的关系有关的解析错误 But I am not even using relations. 但是我什至没有使用关系。 Even a simple query from the local datastore doesn't work. 即使是来自本地数据存储的简单查询也不起作用。

Although I couldn't fix the problem, I discovered what the issue was. 尽管我无法解决问题,但我发现了问题所在。 The issue is related to an underlying bug with the Parse SDK of Android: ParseQuery gives 0 objects when querying from local datastore even after successfully pinning 此问题与Android的Parse SDK的潜在错误有关: 从本地数据存储区进行查询时,即使成功固定后,ParseQuery也会提供0个对象

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM