Robrowski / GeoSnap

Repository for my projects in CS 403x (Mobile and Ubiquitous) at WPI
1 stars 0 forks source link

Discuss discovery querying and image download pipeline/process #7

Open mscosti opened 9 years ago

mscosti commented 9 years ago

We need to figure out the flow of how/when we actually communicate with geosnap server for a discovery query (ask if we are within any radius and get their info), and how/when we will go about downloading them to the phone.

Currently a service is publishing to a location listener receiver.
Photo downloads are implemented as an async task.

Missing is talking with geosnap server.

I propose that the Location Receiver creates an Intent service when the location changes. This intent service will do the job of first contacting our server, and then also download the images IN THE SAME SERVICE INTENT. This means re-factoring photo downloading out of that async task into one service intent with the query request.

If these were separate than we would likely have an ugly set of intent services calling a receiver who starts another intent service, who alerts a different receiver.

Another reason, broadcast receivers should not start async tasks: http://stackoverflow.com/questions/21743800/call-asynctask-from-broadcast-receiver-android

Robrowski commented 9 years ago

Yes, except you should still use the Async so that you can more easily release system resources (services run in the apps main thread while Async tasks don't) while waiting for the images to come in. Also, easier to do parallel requests with Async task.

Its as easy as the service implementing OnImgurResponseListener for that part anyways. (And the trivial bit of making GetService take a Context instead of an Activity)

mscosti commented 9 years ago

that isn't true for intent services, they run in the background, so we can do everything there. since intent services run in the background it doesn't make sense to use an async task in addition.

Robrowski commented 9 years ago

IntentService's can't handle parallel requests, which I suppose is the only remaining reason to use Async tasks.

mscosti commented 9 years ago

they aren't designed to be run from service intents however. if you really want to multithread the downloads, you have to spawn your own threads.

http://stackoverflow.com/questions/13491049/start-async-task-from-onhandleintent

Robrowski commented 9 years ago

oh god. parallel seems like not worth in this plan

mscosti commented 9 years ago

exactly. do you have another plan? where would you propose launching the async tasks if we were to run parallel? I'm not sure it is entirely worth it.

Robrowski commented 9 years ago

i already answered that (in the service) and we shot it down