我不想面对这个错误: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();
}
}
});
答案 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();
}
}
});
}