2

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?

Luis Pereira
  • 1,481
  • 3
  • 19
  • 46
  • seems like it is because of https://developer.android.com/training/monitoring-device-state/doze-standby.html#testing_doze – Pavneet_Singh Jul 20 '17 at 15:22
  • I see, but shouldn't doze be kicked after a while? I mean, I think on Android O is kicked right after screen is off, but in Marshmallow it also applies? – Luis Pereira Jul 20 '17 at 15:41
  • you mentioned `When the user is on battery save mode` seems like making it more restrictive , rest i am not 100% sure – Pavneet_Singh Jul 20 '17 at 15:49
  • oh yea, but then how would I make a viable request? Doze kicks in and cuts internet connection while user is using the application. For the user point of view, if he has low battery and wants to listen music e.g., he will not know why the application stopped working and will blame the faulty app... – Luis Pereira Jul 20 '17 at 19:32
  • 1
    you can look into this https://stackoverflow.com/questions/32627342/how-to-whitelist-app-in-doze-mode-android-6-0 – Pavneet_Singh Jul 21 '17 at 13:44
  • if your network call take long time, you could make it in bounded service .. telling the user what app do. visible part of app take the highest priority. so system couldn't kill it. – Mohamed Ibrahim Oct 26 '17 at 02:27

0 Answers0