问题描述:

I was trying to all the data from different table thus I tried to use this method. However, I understand for loop is synchronous thus the loop didn't stop when the parse is fetching data. Did anyone the get idea how to solve it? Is there got any parse method or some intent services that may help this situation?

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();

}

网友答案:

You can use locks:

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();
}
相关阅读:
Top