I've referred to this answer already and it seems to be related to Retrofit v1.
Goal -> To reduce cold start time by making ObjectMapper work on non-main thread. This image shows a stack trace of it happening on the main thread.
Setup:
compile "com.squareup.retrofit2:retrofit:2.1.0"
compile "com.squareup.retrofit2:converter-jackson:2.1.0"
compile "com.squareup.retrofit2:adapter-rxjava:2.1.0"
compile 'io.reactivex:rxjava:1.1.9'
This is configuration for retrofit
.addCallAdapterFactory(RxJavaCallAdapterFactory.createWithScheduler(Schedulers.io()))
.addConverterFactory(JacksonConverterFactory.create(ObjectMapperFactory.getObjectMapper()))
Below is a typical example of making a network call
compatibilityService().isCompatible()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(response -> { ...});
Within the JacksonConverterFactory the objectmapping seems to work on the main thread.
What is the solution without moving away from RxJava?
Possibly related posts
- Retrofit2.0 using with rxjava will do costly reflection in mian thread even using subscribeOn()
- https://github.com/ReactiveX/RxJava/issues/4347