public List<QiangYu> load() {
BmobQuery<QiangYu> query = new BmobQuery<QiangYu>();
query.findObjects(UiUtils.getContext(), new FindListener<QiangYu>() {
@Override
public void onSuccess(List<QiangYu> list) {
//这个list是不为空的.我想问的是如何把这个list数据在load方法中返回出去.
//因为耗时.这样直接返回是null.
}
}
@Override
public void onError(int arg0, String arg1) {
};
});
//因为onSuccess耗时.这样写,会直接返回null
//有什么办法,可以让onSuccess完成,获取好数据在返回???
return list;
}
Asynchronous requests should not be returned like this, callbacks should be used.
Write an interface, call the interface method in onSuccess, and then call back when using it
It is recommended that you first learn the link description of callbacks
As mentioned above, asynchronous tasks are implemented using interfaces, and it is best to deal with thread issues when calling interface methods.
rxjava is a good choice
I don’t understand why you need to repackage it. In fact, Bmob is already packaged. If you need it, just write an interface callback
Passing above. . . You'll find it's of no use. . . So just use the Bmob callback interface for the interface! No need to do anything unnecessary! !
1. Perform time-consuming operations in asynchronous threads
2. After the query is completed, you can use EventBus or RxBus to send messages to the main thread
3. The main thread accepts events and then refreshes# 🎜🎜# or
Use the RxJava
mentioned above