2017-01-12 7 views
0

ObservableとのRxAndroidBle接続ステータスの監視を設定しようとしています。以下のコードはコンパイルされています(私はそれをまだテストすることができません)が、私は完全になぜ理解していません。 subscribeコールの2番目のパラメータはAction1<java.lang.Throwable> onErrorとなっています。私はこれを正しく実装しましたか?なぜ私がしようとしたとき、私はちょうど、第二の「スロー可能オブジェクトが」フラグが立てられているサブスクリプションのThrowable onErrorコンポーネントが期待通りにコンパイルされない

throwable -> throw throwable 

を書き込むことはできません「のシンボルを解決することはできません 『スロー可能オブジェクト』」、との間に「 - >」と、それはそれはどちらか期待していますと言い、「投げます」右の括弧、左の括弧、またはセミコロン。私はトラブルAction1<Throwable>の概念の周りに私の心をラップを抱えている

// set up monitoring of connection state with a subscription 
boolean setConnectionStateNotification() { 
    asBleDevice.observeConnectionStateChanges() 
     .subscribe(
      connectionState -> asBleConnectionState = connectionState, 
      throwable -> new RuntimeException("Problem with subscription to Connection State Changes: " 
          + throwable.getMessage()) 
      ); 
    return true; 
} 

TBH。誰かがそれを説明できますか?

更新:私はそれを理解したかもしれないと思います。これと同じように:

boolean setConnectionStateNotification() { 
    asBleDevice.observeConnectionStateChanges() // returns Observable<RxBleConnection.RxBleConnectionState> 
     .subscribe(
      connectionState -> asBleConnectionState = connectionState, 
      throwable -> { throw new RuntimeException(
       "Problem with subscription to Connection State Changes: " 
        + throwable.getMessage(), throwable); 
      }, 
      () -> RxBleLog.d("Connection State Observable has completed", null) // onCompleted() with no arguments 
      ); // subscribe 
    return true; 
} 

(私もonCompleted()呼び出しのために、第三のオプションハンドラを追加しました。)

+0

こんにちは。達成したいことを正確に記述できますか? –

答えて

0

私は、これは正しいかもしれないと思う:

boolean setConnectionStateNotification() { 
    asBleDevice.observeConnectionStateChanges() // returns Observable<RxBleConnection.RxBleConnectionState> 
     .subscribe(
      connectionState -> asBleConnectionState = connectionState, // save value 
      throwable -> { throw new RuntimeException(
       "Problem with subscription to Connection State Changes: " 
        + throwable.getMessage(), throwable); 
      }, 
      () -> RxBleLog.d("Connection State Observable has completed", null) // onCompleted() with no arguments 
     ); // subscribe 
    return true; 
} 
関連する問題