Charlie/Skink  Thanks a lots.. for clearing the doubts..  I already know most 
of the underlying concepts (HttpCleint, JSON, xmlRPC), and will take over now.

Charlie, thanks for pointing to the book source code. Skink, thanks for XMLRPC, 
I have downloaded it, will have a look tonight. (I dont see any documentation 
!!).

Thanks
SN



----- Original Message ----- 
From: "Charlie Collins" <[email protected]>
To: "Android Developers" <[email protected]>
Sent: Saturday, December 13, 2008 5:35 PM
Subject: [android-developers] Re: continuously polling webserver for updates.



Yes, many Android applications use the network for data, it is very
common.  I have several that do so, and that includes binary data
(images).

For the upcoming Manning book Unlocking Android I wrote a
"NetworkExplorer" sample app that does a bunch of networking stuff and
demonstrates various approaches.  All the sample apps are hosted on
Google Code, so you can grab the apps and see some examples without
having ot buy the book (the book rocks too, but that's not the point
here ;)).

http://code.google.com/p/unlocking-android/

I find the HttpRequestHelper there, which uses HttpClient (and does
the request in a separate thread with a callback for you), to be
pretty handy:
http://unlocking-android.googlecode.com/svn/chapter6/trunk/NetworkExplorer/src/com/msi/manning/network/data/HTTPRequestHelper.java.
They key is to combine Android "Handler" and HttpClient
"ResponseHandler" and run your requests outside of the UI thread and
respond to callbacks.

In that example app I don't specifically have JSON going on, as I was
focusing more on the networking itself (HTTP, HTTPS, basic
authentication, Google ClientLogin token, etc) - but I do make calls
to the del.icio.us REST-like API (XML), and a few other things. If I
were rolling it all from scratch (not talking to del.icio.us, but
talking to my own server), I would probably use JSON.

You can set an image from the network onto your view as a bitmap.
This is a very crude example (you should cache it if you get it once,
not just do this every time, and it's better to use HttpClient to get
the data), but you get the idea:
URL url = new URL("url string here");
URLConnection conn = url.openConnection();
conn.connect();
BufferedInputStream bis = new BufferedInputStream(conn.getInputStream
());
Bitmap bm = BitmapFactory.decodeStream(bis);
bis.close();
ReviewDetail.this.reviewImage.setImageBitmap(bm);

As for running a Service all the time, that's generally discouraged.
It's Ok to run the Service while your app is running, to poll data for
your app, but after your app is shut down you should shut the Service
down too in 98% of cases (especially if it's a heavyweight thing that
is pulling network data).  See Dianne Hackborn's comments on this
thread: 
http://groups.google.pl/group/android-developers/browse_thread/thread/fa2848e31636af70.

I admit that I do have a few apps where a Service just runs all the
time (start at BOOT_COMPLETED and never get killed - like
WeatherReporter in the book samples), and they pull some minimal data
on a non aggressive schedule (every hour say), but you have to be
really careful with those. I guess the consensus is that "light" long
running services are needed in some cases, but the user should be
given the option of whether or not they want them running (make it an
option, tell the user, don't just make it stealthy).





On Dec 12, 7:44 am, "Android geek" <[email protected]> wrote:
> Thanks Charlie,
>
> I already have some experience of HttpClient, so it wouldn't be difficult.
>
> JSON: Yes, it will be easier and lightweight in comparision to XML and can
> replace XML.
>
> Data: Is it possible to host images on the server and still display on
> views, say imageview ?
>
> Again, I just want to know, if any one is using the similar technique for
> communication between android app and web application. There are lots of
> social networking apps, I think they all must be relying on the similar
> architecture.
>
> Again, my app need to get updates frequently. that is, a service needs to be
> running in background all the time, which polls server for say every minitue
> for updates, and gets data in the form of JSON or XML.
>
> Any comments on this type of architecture? is it fine to poll so frequently.
> (Actually app needs semi-realtime data from the server )
>
> Thanks
>
> ----- Original Message -----
> From: "Charlie Collins" <[email protected]>
> To: "Android Developers" <[email protected]>
> Sent: Friday, December 12, 2008 4:54 PM
> Subject: [android-developers] Re: continuously polling webserver for
>
> updates.
>
> Communication: yes, HttpClient is the best option - you can also use
> plain java.net calls, but HttpClient is a lot easier and handles all
> the heavy lifting for you.
>
> Data: I would say use JSON if you can control the server side. Make a
> REST API on the server and return JSON. Then parse the JSON in
> Android, it's easy, Android has built in support for JSON (and then
> your API would also be usable outside of Android, if need be). The
> other alternative is XML, yes, Android supports that pretty well too,
> just JSON is smaller. As for binary data (images), that's tougher for
> both JSON and XML, but can be done by encoding/serializing to base64.
> That's gonna be slow though. Maybe you could host the images on the
> server and just use pointers to the URLs in your app (that has
> downsides too, but if you don't have a lot of them, and it's already a
> web focused app that has to be online. . . . .).
>
> On Dec 12, 1:22 am, "Android geek" <[email protected]> wrote:
> > Hello devs,
>
> > I am developing an application that continiously needs to poll webserver
> > for updates (Assume that its a messanger like application). There's a web
> > application running on the webserver. the web application can send data
> > such as images and text to the android app.
>
> > I have fundamental understanding of developing apps with android. But here
> > I want your inputs.
>
> > What's available for communication between android app and web application
> > ?, HttpClient can be used, any other alternative?
>
> > How to transfer data between app and webapplication, may be XML? then what
> > about images?
>
> > Please let me know if you have any idea, reply me even if you dont know
> > the exact solution but you can just give me hints.
>
> > Thanks

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to