How to call .start on HandlerThread from .map operator

159
December 21, 2018, at 8:00 PM

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, ":");
    }
}
Answer 1

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;
});
Rent Charter Buses Company
READ ALSO
What should I change to run my App on API 21 android

What should I change to run my App on API 21 android

I have API 21 android mobile and I want to run android app on my own mobile but I know that I did so many mistakes in build gradle fileI just want to know in where to change in gradle file and wht to change so that I can run app on api 21 android? I also want to put code or my gradle...

136