the best and easier way i can figure is to use the Android Cloud to
Device Messaging service, using the underlying google sync connection
that it's already running.

http://code.google.com/android/c2dm/index.html

You can see also the chrometophone extension code to see a working
implementation: http://code.google.com/p/chrometophone/

This has a drawback, it only works on 2.2 devices. If you need to work
without the google assistance, you have to do something  like the
google sync client does in the device, and i think that it's not part
from the android open source, so you can't see the code. As far as I
know, it works also with a service, opening a connection, but it's a
special kind of connection  because it has a long timeout, and it let
the device to go to sleep, wakening it when it receive a response. It
has also some alarms to reopen the connection if it is closed.

I have found this blog post that explain a lot better and have some
code examples:
http://devtcg.blogspot.com/2009/01/push-services-implementing-persistent.html




On 15 jul, 15:41, Namrata <[email protected]> wrote:
> > Do you really need to have a socket open at all times?
>
> yes, my application is based on push technique for which I always need
> to keep it open
>
> >only keep the socket open while the user is actually using the application.
>
> yup I am doing it. Actually the fuctionality of app includes
> minimization of app and still listening to server push.
>
> On Jul 15, 6:24 pm, Miguel Morales <[email protected]> wrote:
>
>
>
> > Do you really need to have a socket open at all times?  Why not
> > periodically check the server using an Alarm, or only keep the socket
> > open while the user is actually using the application.  Also, any loop
> > will drain your battery, you might try sleeping at the end of it.
>
> > On Thu, Jul 15, 2010 at 5:39 AM, Namrata <[email protected]> wrote:
> > > Thanks Mark..
>
> > > On Jul 15, 5:06 pm, Mark Murphy <[email protected]> wrote:
> > >> On Thu, Jul 15, 2010 at 7:56 AM, Namrata <[email protected]> 
> > >> wrote:
> > >> > any answer?..This is blocking issue for me as it drains batter in
> > >> > couple of hours.
>
> > >> You may wish to watch the C2DM presentation from Google I|O 2010, as
> > >> they provide a few hints on how they try to minimize battery usage.
>
> > >> --
> > >> Mark Murphy (a Commons 
> > >> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> > >> _Android Programming Tutorials_ Version 2.9 Available!
>
> > > --
> > > 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
>
> > --http://developingthedream.blogspot.com/,http://diastrofunk.com,http:/..., 
> > ~Isaiah 55:8-9

-- 
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