ʕ ᵔᴥᵔ ʔ ʕ ᵔᴥᵔ ʔ - 3 years ago 261
Android Question

Http request in background with Firebase job dispatcher: asynchronous or synchronous?

I am using Firebase Job Dispatcher and setting it up like described in https://github.com/firebase/firebase-jobdispatcher-android/blob/master/README.md.

The job to be scheduled is a http request. The http request could run while the app is on the foreground (the user is looking at it), or while the app is in the background/not started.

Should the http request (using the okhttp library) be put in a separate thread / asynchronous or can I just call it directly from the JobService?

Answer Source

JobService extends Service so it runs on the main thread. Therefore, you shouldn't be able to make network calls directly. However, there is SimpleJobService where you can make direct calls.

I think using SimpleJobService is better than using AsyncTask within JobService because it already does it in its own way as you can see here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download