2017-12-28 24 views
0
他のstackoverflowの質問にこれらの答えで

https://stackoverflow.com/a/41360829/1932522https://stackoverflow.com/a/40557237/1932522TaskCompletionSourceの使用は、タスク内遅れる呼び出しを実行できるように作成する方法を示して提供されている例があります。取得TaskCompletionSource作業(FirestoreためのAndroidのタスク)

これを簡単な例で実装すると、コンパイラが最初のパラメータとしてタスクを期待しているので、.continueWith(new TaskerB()));という行がコンパイルされないという問題が発生します。このパラメータは、 String型?誰がこのコードを動作させるのに役立ち、どのように成功して使用するにはTaskCompletionSourceを使用するかを私に説明することができます。

注:例は非常に簡単です。実際にはFirestoreのアクションを実行し、リスナーを設定してリスナーの内側からtcs.setResult(..)を呼び出します。代わりに

public class StartTask implements Callable<Integer>{ 
     @Override 
     public Integer call() throws Exception { 
      return 1; 
     } 
    } 

    public class TaskerA implements Continuation< Integer, Task<String>>{ 
     @Override 
     public Task<String> then(@NonNull Task<Integer> task) throws Exception { 
      final TaskCompletionSource<String> tcs = new TaskCompletionSource<>(); 
      tcs.setResult("value: " + task.getResult()); 
      return tcs.getTask(); 
     } 
    } 

    public class TaskerB implements Continuation< String, Void>{ 
     @Override 
     public Void then(@NonNull Task<String> task) throws Exception { 
      Log.d(TAG, "Output is: " + task.getResult()); 
      return null; 
     }; 
    } 

    public void runExample(){ 
     Tasks.call(new StartTask()) 
      .continueWith(new TaskerA()) 
      .continueWith(new TaskerB())); 
    } 

答えて

関連する問題