• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Services, in web, concurrent and all?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
William Martinez
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ed.
Actually sounds like a good support. And thanks for the source code link!


William Martinez Pomares.
Architect's Thoughts
 
Ed Burnette
Author
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See also:
https://coderanch.com/t/435293/Android/Mobile/Running-background-Services-schedule
 
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic