2017-04-20 64 views
0

我已經創建了兩個任務對火力datbase寫入數據如何在FirebaseDatabase

class EventDataAddingTask implements Continuation<User, Task<Boolean>> { 
     @Override 
     public Task<Boolean> then(Task<User> task) { 
      final TaskCompletionSource<Boolean> tcs = new TaskCompletionSource(); 
      mUserEventsRefrence.child(user.getUid()).setValue(addEditEventData) 
        .addOnCompleteListener(new OnCompleteListener<Void>() { 
         @Override 
         public void onComplete(@NonNull Task<Void> task) { 
          if(task.isSuccessful()){ 
           tcs.setResult(true); 
          } 
         } 
        }).addOnFailureListener(new OnFailureListener() { 
         @Override 
         public void onFailure(@NonNull Exception error) { 
          tcs.setResult(false); 
          tcs.setException(error); 
         } 
        }); 
      return tcs.getTask(); 
     } 
    } 



class UserPaymentAddingTask implements Continuation<User, Task<Boolean>> { 
     @Override 
     public Task<Boolean> then(Task<User> task) { 
      final TaskCompletionSource<Boolean> tcs = new TaskCompletionSource(); 
      mUserPaymentDetailsRefrence.child(user.getUid()).setValue(addEditUserPaymentData) 
        .addOnCompleteListener(new OnCompleteListener<Void>() { 
         @Override 
         public void onComplete(@NonNull Task<Void> task) { 
          if(task.isSuccessful()){ 
           tcs.setResult(true); 
          } 
         } 
        }).addOnFailureListener(new OnFailureListener() { 
       @Override 
       public void onFailure(@NonNull Exception error) { 
        tcs.setResult(false); 
        tcs.setException(error); 
       } 
      }); 
      return tcs.getTask(); 
     } 
    } 

我不知道該怎麼辦好這兩個任務,這樣,當一個任務完成和其他運行自動運行倍數任務並在任務成功完成時向用戶顯示消息

回答

相關問題