0

I am learnign how to handle and to use functional programming in Android. So I developed the below code. I would like to handle the HandlerThread as observable, but when I try to call .start() from .map() operator I receive the following error:

    no instances of type variable(s) R exists so that  void conforms to R

please let me know why I am getting this error and how to solve it.

code:

public Single<HandlerThread> getObsInitializedHandlerThread() {
    this.mMyHandlerThread = new MyHandlerThread(NAME_MY_HANDLER_THREAD);
    return Single.just(this.mMyHandlerThread);
}

@Override
protected void onResume() {
    super.onResume();
    String TAG_LOG = ActMain.TAG_LOG + "." + "onResume()";
    Log.v(TAG_LOG, ":");

    this.getObsInitializedHandlerThread()
            .map(mMyHandlerThread -> mMyHandlerThread.start());
}

private class MyHandlerThread extends HandlerThread {

    public MyHandlerThread(String name) {
        super(name);
        String TAG_LOG = ActMain.class.getSimpleName() + "." + "MyHandlerThread() Constructor";
        Log.v(TAG_LOG, ":");
    }

    @Override
    protected void onLooperPrepared() {
        super.onLooperPrepared();
        String TAG_LOG = ActMain.class.getSimpleName() + "." + onLoopPrepared()";
        Log.v(TAG_LOG, ":");
    }
}
user10776303
  • 241
  • 6
  • 16
  • Why would you do that? I mean you normally use `Observable` for emitting real data. I would never want an emitter to emit `HandlerThread`. – GVillani82 Dec 21 '18 at 10:52
  • @GVillani82 i am learning functional programming using rxjava..and i want to develop a new code entirly using reactiveX..would you please help me? I am trying to convert it to Maybe but i could not find any method that returns void – user10776303 Dec 21 '18 at 10:54

1 Answers1

0

In map you allways need to return a value (T) you cant return a void so can you trye

 this.getObsInitializedHandlerThread()
        .map(mMyHandlerThread ->{
 mMyHandlerThread.start();
return mMyHandlerThread;
});
Ricard Kollcaku
  • 1,622
  • 5
  • 9