每次我使用Transaction时,都会调用OnComplete
。 OnComplete
方法再次调用我的整个类活动。
有人可以解释一下吗?这是代码:
rate_btn.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Firebase upvoteref = new Firebase("https://myapp.firebaseio.com/"+msgID+"/upvotes");
upvoteref.runTransaction(new Transaction.Handler() {
@Override
public Transaction.Result doTransaction(final MutableData currentData) {
if (currentData.getValue() == null) {
currentData.setValue(1);
} else {
currentData.setValue((Long) currentData.getValue() + 1);
}
return Transaction.success(currentData);
}
public void onComplete(FirebaseError firebaseError, boolean committed, DataSnapshot currentData) {
if (firebaseError != null) {
System.out.println("Firebase counter increment failed.");
} else {
System.out.println("Firebase counter increment succeeded.");
}
}
});
}