aspose file tools*
The moose likes Android and the fly likes Services, in web, concurrent and all? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Services, in web, concurrent and all?" Watch "Services, in web, concurrent and all?" New topic
Author

Services, in web, concurrent and all?

William Martinez
Greenhorn

Joined: Jan 25, 2008
Posts: 5
Hello.
Not quite sure if you cover this in the chapter named The Connected World, but some the times the phone may be a front-end device where a client app consumes back-office services. That means we will need at least HTTP to do some requests. Is there any web services (read SOAP) or REST helper libraries?
How is the usual service consumption treated in mobile, and particular Android.

Now, as opposed to iPhone, Android does allow for concurrency (I mean, several tasks running in my app). Is there a model for a back - thread that frequently consumes a service to simulate a "push" of information into the phone? Imaging people that want to continuously post their position into a mapping system. Ideas for that?

Thanks.

William Martinez.
Ed Burnette
Author
Ranch Hand

Joined: Jun 10, 2003
Posts: 142
You can call web services because the regular Java socket and URL calls are there. The trick is to not block the foreground UI thread. Calling a web service is covered in chapter 7 of my book and in the free sample code here: http://www.pragprog.com/titles/eband/source_code (Translate example). REST and JSON are built-in, but with some extra work you can do SOAP (search this forum for links).

For most programs, doing network I/O on a different thread within the same program will be fine. However Android does allow you to run code in the background that might not even have a user interface. It may not really be running all the time -- to save battery power you probably want it to run only based on certain events or on a timer.

The Android Service class and the <service> tag in the Android manifest are used to define Services. I don't cover Services in the book since most people won't need them. However I do cover Content Providers, which is one way your app can cause code from another app (like the Contacts database provider) to be started in order to fulfill a request.

For documentation on Services see:
http://developer.android.com/reference/android/app/Service.html
http://developer.android.com/guide/topics/fundamentals.html#servlife
http://developer.android.com/guide/topics/manifest/service-element.html

Ed Burnette, Author of Hello Android
Blog: ZDNet's Dev Connection - Twitter: @eburnette
William Martinez
Greenhorn

Joined: Jan 25, 2008
Posts: 5
Thanks Ed.
Actually sounds like a good support. And thanks for the source code link!


William Martinez Pomares.
Architect's Thoughts
Ed Burnette
Author
Ranch Hand

Joined: Jun 10, 2003
Posts: 142
See also:
http://www.coderanch.com/t/435293/Android/Mobile/Running-background-Services-schedule
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

This is how I would do this. Maintain a connection to the server using HTTP 1.1 Persistent connections
(if the connection drops, reconnect ad infinitum).

Use COMET or other Ajax push protocols to push new content down to the phone.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Services, in web, concurrent and all?