Parse.com查询findInBackground不返回任何数据 [英] Parse.com query findInBackground doesn't return any data

查看:220
本文介绍了Parse.com查询findInBackground不返回任何数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

功能我下面应该返回所有的学生从parse.com,在code(下评论)名单完全填充了正确的结果但在功能列表的最后一个部分空。我不是很了解这里发生了什么,任何帮助是极大的AP preciated。

 公开名单<学生> getAllStudents(){
    最后的名单,其中,学生> studentList =新的ArrayList<学生>();
    ParseQuery<的parseObject>查询= ParseQuery.getQuery(学生);
    query.findInBackground(新FindCallback<的parseObject>(){
        公共无效完成(名单<的parseObject>清单,ParseException的E){
            如果(E == NULL){
                对于(的parseObject○:名单){
                    学生S =新的学生();
                    s.setObjectId(o.getObjectId());
                    s.setFirstName(o.getString(名字));
                    s.setSurname(o.getString(姓));
                    s.setDOB(o.getString(DOB));
                    s.setInstructor(o.getBoolean(导师));
                    studentList.add(多个);
                }
                // studentList已满这里
            } 其他 {

            }
            // studentList充满来啦
        }

    });
    // studentList是空在这里
    返回studentList;
}
 

解决方案

按<一个href="https://parse.com/docs/android/api/com/parse/ParseQuery.html#findInBackground(com.parse.FindCallback)" rel="nofollow">https://parse.com/docs/android/api/com/parse/ParseQuery.html#findInBackground(com.parse.FindCallback) :公共无效findInBackground(FindCallback回调)
检索ParseObjects满足这个从服务器查询在后台线程的列表。这是preferable使用的找到(),除非你的code在后台线程已经运行。
所以,如果你想引起你的方法使用查找或添加一些通知时FindCallback做他的工作。

the function i have below should return all of the students from parse.com, at one section of code (commented below) the list is fully populated with the correct results however at the end of the function the list is empty. I can't quite understand what is happening here, any help is greatly appreciated.

public List<Student> getAllStudents() {
    final List<Student> studentList = new ArrayList<Student>();
    ParseQuery<ParseObject> query = ParseQuery.getQuery("Student");
    query.findInBackground(new FindCallback<ParseObject>() {
        public void done(List<ParseObject> list, ParseException e) {
            if (e == null) {
                for (ParseObject o : list) {
                    Student s = new Student();
                    s.setObjectId(o.getObjectId());
                    s.setFirstName(o.getString("FirstName"));
                    s.setSurname(o.getString("Surname"));
                    s.setDOB(o.getString("DOB"));
                    s.setInstructor(o.getBoolean("Instructor"));
                    studentList.add(s);
                }
                // studentList is full here
            } else {

            }
            // studentList is full here too
        }

    });
    // studentList is empty here
    return studentList;
}

解决方案

As per https://parse.com/docs/android/api/com/parse/ParseQuery.html#findInBackground(com.parse.FindCallback) : public void findInBackground(FindCallback callback)
Retrieves a list of ParseObjects that satisfy this query from the server in a background thread. This is preferable to using find(), unless your code is already running in a background thread.
So if you want result in your method use find or add some notification when FindCallback did his work.

这篇关于Parse.com查询findInBackground不返回任何数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆