我正在尝试使用不同表中的所有数据,因此我尝试使用此方法。但是,我理解for循环是同步的,因此循环在解析数据时不会停止。有没有人知道如何解决它?是否有任何解析方法或某些意图服务可以帮助解决这种情况?
private void getAllInformation(){
String controlName;
for(int i=0; i<3;i++){
if(i==0){
controlName = AppConfiguration.strEvent;
}
else if(i==1){
controlName = AppConfiguration.strStore;
}
else if (i==2){
controlName = AppConfiguration.strPromotion;
}
else{
return;
}
ParseQuery<ParseObject> query = ParseQuery.getQuery(controlName);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objectList, ParseException e) {
if(e!=null){
Toast.makeText(getApplicationContext(),"Error Loading.Please Try Again",Toast.LENGTH_LONG ).show();
return;
}
if (objectList!= null) {
Toast.makeText(getApplicationContext(),"Success",Toast.LENGTH_LONG ).show();
ParseObject.pinAllInBackground(objectList);
}
else{
Toast.makeText(getApplicationContext(),"Some Data is null!",Toast.LENGTH_LONG ).show();
}
}
});
}
// getAllOfflineInformation();
}
答案 0 :(得分:0)
你可以使用锁:
Object lock = new Object();
ParseQuery<ParseObject> query = ParseQuery.getQuery(controlName);
query.findInBackground(new FindCallback<ParseObject>() {
public void done(List<ParseObject> objectList, ParseException e) {
synchronized (lock) {
lock.notifyAll();
}
if(e!=null){
Toast.makeText(getApplicationContext(),"Error Loading.Please Try Again",Toast.LENGTH_LONG ).show();
return;
}
if (objectList!= null) {
Toast.makeText(getApplicationContext(),"Success",Toast.LENGTH_LONG ).show();
ParseObject.pinAllInBackground(objectList);
}
else{
Toast.makeText(getApplicationContext(),"Some Data is null!",Toast.LENGTH_LONG ).show();
}
}
});
synchronized (lock) {
lock.wait();
}