1

So I'm working on a simple Server/Client Android application where the Android app takes a picture and then sends it to a server.

After that the server has some backend code that will do some sort of processing to the image and generate a new image.

I currently have everything up to here working.

What I now need is a way for the server to let the client(android app) know when the image is ready.

Can somebody point me in the direction of the proper way of doing this? I was thinking something simple like a boolean value of whether or not the new image exists yet. My issue is that the processing may take a second or two so if I were to just simply do a GET there is a good chance the new image is not ready yet/does not exist.

Ultimately I want to display the new processed image in the android app. My current method is just to wait 1 second or two before doing the GET but that seems like a bad a way to do this.

bopbopbee
  • 51
  • 1
  • 5

2 Answers2

1

Yes, the way you are doing it is completely useless.

You need to do some RestFul service there. When client requests to some certain api, you need to hold it there, do your image processing and respond in the same http request back.

RestFul API

Regarding to loader effect, when you implement the restful api on your server side it's easy to do it in the client. In Android you can use AsyncTask, which handles some background operation with onPreExecute and onPostExecute callbacks inside. So you can start your loader animation in onPreExecute and finish and replace the new image in onPostExecute methods.

You can also check out this discussion. SOF Question

Community
  • 1
  • 1
osayilgan
  • 5,873
  • 7
  • 47
  • 68
0

Only a couple of ways, really ... simply have the client "call back" if the server process is anything that exceeds several seconds (a timer on the client). This works, but not the most elegant way of handling things.

My preferred way of tackling long latency server response issues is via a "push" notification to the handset. That way, the handset is free to continue forward with other tasks. But, once the server has something ready it sends the notification - handset receives notification, and "calls home" to pick up the waiting payload. I've been building mobile systems like this since BlackBerry came out with MDS back in 2002. It's an elegant approach, in my opinion. Amazon, Apple, and Google ... they all have their take on this infrastructure that models what RIM pioneered. Check them all out before making any decisions as they each have their own restrictions, pros and cons, costs, etc., etc.

BonanzaDriver
  • 6,411
  • 5
  • 32
  • 35