I'm trying to make two requests when user clicks on a button. However, the request might take a little while.
When the user is on battery save mode and screens lock his device while the request is still being done, the request will not complete and will give a socket timeout exception.
I made a sample project to try this out and you can find it here.
I'm using retrofit and RxJava to make my requests like this:
networkFactory.request()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ result -> Log.d("TAG", "The value is this $result") },
{ error -> Log.e("TAG", "Ohoh an error ${Log.getStackTraceString(error)}")
})
My networkFactory request() is:
fun request(): Observable<Doc> {
return service.request(API_KEY)
}
with the following interface:
@GET("articlesearch.json")
fun request(@Query("api-key") apiKey : String) : Observable<Doc>
Am I doing something wrong here?