有没有办法如何做一个while循环来避免RequestLimitExceeded?

时间:2015-03-04 10:57:59

标签: android parse-platform

我不想面对这个错误:RequestLimitExceeded所以我宁愿创建一个while loop来监听异常并重复自己直到没有RequestLimitExceeded异常。但是,我找不到办法如何做到这一点。

代码:

ParseObject objectUpdate = ParseObject.createWithoutData("HangOut", 
hangOut.getObjectID());
    objectUpdate.put("Name", name.getText().toString());
    objectUpdate.put("City", autocompleteTV.getText().toString());
    objectUpdate.put("City_Lowercase", 
    autocompleteTV.getText().toString().toLowerCase());
    hangOutUpdate.saveInBackground(new SaveCallback() {
        @Override
        public void done(ParseException e) {
    //somewhere here I would like to check if e is RequestLimitExceeded if             
    //yes, then repeat saveInBackground
            if (e==null){
                Toast.makeText(getApplicationContext(),
                        "Object was edited.", Toast.LENGTH_SHORT).show();
                finish();
              }else{
                Toast.makeText(getApplicationContext(),
                        "An error has occured: "+e.toString(), 
    Toast.LENGTH_SHORT).show();
                finish();
            }
        }
    });

1 个答案:

答案 0 :(得分:1)

你需要的是这样的东西吗?

private void save() {
    hangOutUpdate.saveInBackground(new SaveCallback() {
        @Override
        public void done(ParseException e) {
            if (e==null){
                Toast.makeText(getApplicationContext(),
                        "Object was edited.", Toast.LENGTH_SHORT).show();
                finish();
            } else if (e instanceof RequestLimitExceeded) {
                save(); // How many times you do this is your business...
            } else {
                Toast.makeText(getApplicationContext(),
                        "An error has occured: "+e.toString(), 
    Toast.LENGTH_SHORT).show();
                finish();
            }
        }
    });
}