[英]Save ParseObject (subclass) to cloud => [success], pin it immediately => [success], get objects from pinned group [0 results]?
I have a very simple subclass of ParseObject - Wallet
. 我有一个非常简单的ParseObject-
Wallet
子类。 I am creating one new instance and saving it to the cloud via saveEventuall()
and immediately afterwards trying to pin it to localstore (and eventually broadcast a signal to my app so it can update UIs since it reads objects only from the localstore for perfrormance. 我正在创建一个新实例,然后通过
saveEventuall()
将其保存到云中,然后立即尝试将其固定到本地存储(并最终向我的应用广播一个信号,以便它可以更新UI,因为它仅从本地存储读取对象以获取性能。
Here's how I register the subclass in Application.onCreate(): 这是我在Application.onCreate()中注册子类的方式:
public void onCreate() {
super.onCreate();
ParseCrashReporting.enable(this);
ParseObject.registerSubclass(Wallet.class); // <----
Parse.enableLocalDatastore(this);
Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
Parse.initialize(this, "private stuff", "private stuff");
ParseUser.enableAutomaticUser();
ParseACL defaultACL = new ParseACL();
ParseACL.setDefaultACL(defaultACL, true);
ParseInstallation.getCurrentInstallation().saveInBackground();
if (ParseUser.getCurrentUser() == null)
ParseUser.getCurrentUser().signUpInBackground();
}
Here is the full subclass itself: 这是完整的子类本身:
@ParseClassName("Wallet")
public class Wallet extends ParseObject {
public Wallet() {
}
public void putName(String name) {
put("name", name);
}
public String getName() {
return getString("name");
}
public static ParseQuery<Wallet> getQuery() {
return ParseQuery.getQuery(Wallet.class);
}
}
And then a simple save of an object to the cloud, pin it locally and trying to retrieve it from the pin for testing: 然后将对象简单保存到云中,将其固定在本地,然后尝试从该固定中检索它以进行测试:
final Wallet c = new Wallet();
c.putName(name);
c.saveEventually(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e != null) e.printStackTrace();
Log.d(getClass().getSimpleName(), c.getObjectId() + " is the saved object id");
c.pinInBackground("wallet", new SaveCallback() {
@Override
public void done(ParseException e) {
if (e != null) e.printStackTrace();
ParseQuery<Wallet> pq = Wallet.getQuery();
pq.fromPin("wallet");
pq.countInBackground(new CountCallback() {
@Override
public void done(int i, ParseException e) {
Log.d(getClass().getSimpleName(), i + " items in pin after saving one");
}
});
}
});
}
});
And to my surprise, here's what I see in LogCat: 令我惊讶的是,我在LogCat中看到的是:
06-29 11:29:00.279: D/(3480): J6ljTKezMf is the saved object id
06-29 11:29:00.303: D/(3480): 0 items in pin after saving one
What? 什么? I just got the item saved to cloud and then pinned it?
我只是将项目保存到云中,然后固定了吗? How come there are 0 items inside the pin group?
引脚组中为什么有0个项目?
Thoughts? 有什么想法吗?
I believe in Parse, ParseObject
class names are case sensitive. 我相信在Parse中,
ParseObject
类名称区分大小写。 In your code, you've got the line pq.fromPin("wallet");
在您的代码中,您已经获得了
pq.fromPin("wallet");
, but you have declared your class as "Wallet"
so no results are being returned. ,但是您已将您的课程声明为
"Wallet"
因此不会返回任何结果。 Try changing "wallet"
to "Wallet"
in that line. 尝试在该行中将
"wallet"
更改为"Wallet"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.