为什么OnComplete会回忆课堂活动? Firebase Android

时间:2015-03-14 00:00:09

标签: android transactions firebase firebase-realtime-database

每次我使用Transaction时,都会调用OnCompleteOnComplete方法再次调用我的整个类活动。

有人可以解释一下吗?这是代码:

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.");
            }
        }
    });
}

0 个答案:

没有答案