[android-developers] Re: interfacing to a server via http with a service

2011-02-07 Thread Avtar Khalsa
Thanks for the reply. I did look over the service documentation, and
its clear to me that I need to use AIDL to accomplish the type of
communication I need. That said, I don't need the service to run with
separate applications, so it should just be a local service. My
confusion is really just over whether or not I can use AIDL to
communicate with a local service, or if it is only for remote
services?

Thanks again for any insight.

On Feb 6, 11:48 pm, TreKing treking...@gmail.com wrote:
 On Sun, Feb 6, 2011 at 5:25 PM, Avtar Khalsa akhals...@gmail.com wrote:
  I know it will require a binding, but since it is a local service, I am
  unsure if I should use AIDL, or something else.

 Have you reviewed the Service documentation? It's pretty detailed, with some
 samples on local and remote services.

 --- 
 --
 TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
 transit tracking app for Android-powered devices

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


Re: [android-developers] Re: interfacing to a server via http with a service

2011-02-07 Thread Mark Murphy
You do not need AIDL for a local service.

On Mon, Feb 7, 2011 at 8:20 PM, Avtar Khalsa akhals...@gmail.com wrote:
 Thanks for the reply. I did look over the service documentation, and
 its clear to me that I need to use AIDL to accomplish the type of
 communication I need. That said, I don't need the service to run with
 separate applications, so it should just be a local service. My
 confusion is really just over whether or not I can use AIDL to
 communicate with a local service, or if it is only for remote
 services?

 Thanks again for any insight.

 On Feb 6, 11:48 pm, TreKing treking...@gmail.com wrote:
 On Sun, Feb 6, 2011 at 5:25 PM, Avtar Khalsa akhals...@gmail.com wrote:
  I know it will require a binding, but since it is a local service, I am
  unsure if I should use AIDL, or something else.

 Have you reviewed the Service documentation? It's pretty detailed, with some
 samples on local and remote services.

 --- 
 --
 TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
 transit tracking app for Android-powered devices

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




-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android 2.3 Programming Books: http://commonsware.com/books

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


[android-developers] Re: interfacing to a server via http with a service

2011-02-07 Thread Avtar Khalsa
If I don't need AIDL, then my original question remains. I am just
unsure how to send an object containing information from the local
service to an activity its bound to. The Service documentation doesn't
show how to send information from the service to an activity any way
except using AIDL for remote services?

On Feb 7, 8:23 pm, Mark Murphy mmur...@commonsware.com wrote:
 You do not need AIDL for a local service.









 On Mon, Feb 7, 2011 at 8:20 PM, Avtar Khalsa akhals...@gmail.com wrote:
  Thanks for the reply. I did look over the service documentation, and
  its clear to me that I need to use AIDL to accomplish the type of
  communication I need. That said, I don't need the service to run with
  separate applications, so it should just be a local service. My
  confusion is really just over whether or not I can use AIDL to
  communicate with a local service, or if it is only for remote
  services?

  Thanks again for any insight.

  On Feb 6, 11:48 pm, TreKing treking...@gmail.com wrote:
  On Sun, Feb 6, 2011 at 5:25 PM, Avtar Khalsa akhals...@gmail.com wrote:
   I know it will require a binding, but since it is a local service, I am
   unsure if I should use AIDL, or something else.

  Have you reviewed the Service documentation? It's pretty detailed, with 
  some
  samples on local and remote services.

  ---
   --
  TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
  transit tracking app for Android-powered devices

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

 --
 Mark Murphy (a Commons 
 Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy

 Android 2.3 Programming Books:http://commonsware.com/books

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


Re: [android-developers] Re: interfacing to a server via http with a service

2011-02-07 Thread TreKing
On Mon, Feb 7, 2011 at 7:52 PM, Avtar Khalsa akhals...@gmail.com wrote:

 If I don't need AIDL, then my original question remains. I am just unsure
 how to send an object containing information from the local service to an
 activity its bound to.


Look at the Local Service example in the docs again. Specifically this
class:
http://developer.android.com/reference/android/content/ServiceConnection.html


 The Service documentation doesn't show how to send information from the
 service to an activity any way except using AIDL for remote services?


Not explicitly, no, but it shows you how to get at the running Service,
through which you can get and set data as required.

-
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

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

[android-developers] Re: interfacing to a server via http with a service

2011-02-07 Thread Avtar Khalsa
I saw that, and initially thought it could help me. However, the local
service example and the class you specifically referred to only seem
to accommodate messages from the service onServiceConnected and
onServiceDisconnected. This does not really help me since my activity
will be launching the service and then will need the service to notify
it once the information from my server has been successfully
downloaded. I don't see anything other than AIDL that will let the
service inform the activity that it is ready to send an object
containing information from the server. Am I reading the documentation
incorrectly?


On Feb 7, 9:19 pm, TreKing treking...@gmail.com wrote:
 On Mon, Feb 7, 2011 at 7:52 PM, Avtar Khalsa akhals...@gmail.com wrote:
  If I don't need AIDL, then my original question remains. I am just unsure
  how to send an object containing information from the local service to an
  activity its bound to.

 Look at the Local Service example in the docs again. Specifically this
 class:http://developer.android.com/reference/android/content/ServiceConnect...

  The Service documentation doesn't show how to send information from the
  service to an activity any way except using AIDL for remote services?

 Not explicitly, no, but it shows you how to get at the running Service,
 through which you can get and set data as required.

 --- 
 --
 TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
 transit tracking app for Android-powered devices

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


Re: [android-developers] Re: interfacing to a server via http with a service

2011-02-07 Thread TreKing
On Mon, Feb 7, 2011 at 8:35 PM, Avtar Khalsa akhals...@gmail.com wrote:

  However, the local service example and the class you specifically referred
 to only seem to accommodate messages from the service onServiceConnected
 and onServiceDisconnected.


Those are the explicit events the ServiceConnection get. Notice in the
example when the service is started, the connection object grabs a reference
to the Service. The ServiceConnection itself is referenced in the Activity.
Therefore you can get at the Service reference from your Activity through
the ServiceConnection.


 This does not really help me since my activity will be launching the
 service and then will need the service to notify it once the information
 from my server has been successfully downloaded.


Services are usually for maintaining an ongoing background task. Binding to
them is usually for showing the state of that background task to the user
(and possibly give them control over it). Think music player.

If you're just trying to download some data while your Activity is alive, an
AsyncTask within your Activity may be much, much simpler.

-
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

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

[android-developers] Re: interfacing to a server via http with a service

2011-02-07 Thread Avtar Khalsa
Thanks for the reply again. It was quite helpful. I am actually
downloading small audio files for an answering machine app. If the
activity that launched the service is still running, I would like it
to update to include the newly downloaded files in the UI for the user
to listen to. If the user has moved to a different activity, I just
want the service to save the file to persistent storage. (It will
store to persistent storage either way, but if the activity is running
the UI should update) A service seems appropriate here although I am
certainly open to other options?

I understand that I can get a reference to the service from the
activity, and how I could pass information with it. The issue I am
having specifically is notifying the activity that the download is
complete. I would really rather avoid having the activity poll the
service to find out if the download is completed.



On Feb 7, 9:53 pm, TreKing treking...@gmail.com wrote:
 On Mon, Feb 7, 2011 at 8:35 PM, Avtar Khalsa akhals...@gmail.com wrote:
   However, the local service example and the class you specifically referred
  to only seem to accommodate messages from the service onServiceConnected
  and onServiceDisconnected.

 Those are the explicit events the ServiceConnection get. Notice in the
 example when the service is started, the connection object grabs a reference
 to the Service. The ServiceConnection itself is referenced in the Activity.
 Therefore you can get at the Service reference from your Activity through
 the ServiceConnection.

  This does not really help me since my activity will be launching the
  service and then will need the service to notify it once the information
  from my server has been successfully downloaded.

 Services are usually for maintaining an ongoing background task. Binding to
 them is usually for showing the state of that background task to the user
 (and possibly give them control over it). Think music player.

 If you're just trying to download some data while your Activity is alive, an
 AsyncTask within your Activity may be much, much simpler.

 --- 
 --
 TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
 transit tracking app for Android-powered devices

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


Re: [android-developers] Re: interfacing to a server via http with a service

2011-02-07 Thread TreKing
On Mon, Feb 7, 2011 at 9:24 PM, Avtar Khalsa akhals...@gmail.com wrote:

 Thanks for the reply again. It was quite helpful. I am actually downloading
 small audio files for an answering machine app. If the activity that
 launched the service is still running, I would like it to update to include
 the newly downloaded files in the UI for the user to listen to. If the user
 has moved to a different activity, I just want the service to save the file
 to persistent storage. (It will store to persistent storage either way, but
 if the activity is running the UI should update) A service seems appropriate
 here although I am certainly open to other options?


I guess it depends on the flow and user workflow of your app. If you start
your app, it begins downloading, updates the UI as things becomes available,
and then shuts down and stops the downloading when the user exist the
Activity, then I would suggest an AsyncTask.

If the user expects the downloads to continue and somehow play or be
notified as they become available, then yeah, a Service seems more
appropriate.

Ultimately, either way will work.


 The issue I am having specifically is notifying the activity that the
 download is complete. I would really rather avoid having the activity poll
 the service to find out if the download is completed


You've seen how most of the UI in Android works? Nearly everything registers
a Listener object when it wants to know something happens. Create your own
listener class like ServiceListener or something. Your service takes a
reference and hold on to it. When a download is complete, it invokes the
listener's onDownloadComplete() method (or whatever you want to call it).

Meanwhile the Activity is the one that creates an instance of a custom
listener and passes it to the service. When the service call it's method, it
responds appropriately (updating the UI).

You could also send a Broadcast that the Activity would register for, which
would set you up for more advance functionality like background downloading
and responding to downloading completing without needing your activity to be
alive and waiting for the listener to get triggered. Just an idea though,
the former option is much easier and should suit your current problem just
fine.

-
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

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

[android-developers] Re: interfacing to a server via http with a service

2011-02-07 Thread Avtar Khalsa
I do need the downloads to continue when the application switches
activities, which is why I am using a service in the first place. It
sounds like registering a listener is the way to go. Thank you so much
for the help!

On Feb 7, 10:34 pm, TreKing treking...@gmail.com wrote:
 On Mon, Feb 7, 2011 at 9:24 PM, Avtar Khalsa akhals...@gmail.com wrote:
  Thanks for the reply again. It was quite helpful. I am actually downloading
  small audio files for an answering machine app. If the activity that
  launched the service is still running, I would like it to update to include
  the newly downloaded files in the UI for the user to listen to. If the user
  has moved to a different activity, I just want the service to save the file
  to persistent storage. (It will store to persistent storage either way, but
  if the activity is running the UI should update) A service seems appropriate
  here although I am certainly open to other options?

 I guess it depends on the flow and user workflow of your app. If you start
 your app, it begins downloading, updates the UI as things becomes available,
 and then shuts down and stops the downloading when the user exist the
 Activity, then I would suggest an AsyncTask.

 If the user expects the downloads to continue and somehow play or be
 notified as they become available, then yeah, a Service seems more
 appropriate.

 Ultimately, either way will work.

  The issue I am having specifically is notifying the activity that the
  download is complete. I would really rather avoid having the activity poll
  the service to find out if the download is completed

 You've seen how most of the UI in Android works? Nearly everything registers
 a Listener object when it wants to know something happens. Create your own
 listener class like ServiceListener or something. Your service takes a
 reference and hold on to it. When a download is complete, it invokes the
 listener's onDownloadComplete() method (or whatever you want to call it).

 Meanwhile the Activity is the one that creates an instance of a custom
 listener and passes it to the service. When the service call it's method, it
 responds appropriately (updating the UI).

 You could also send a Broadcast that the Activity would register for, which
 would set you up for more advance functionality like background downloading
 and responding to downloading completing without needing your activity to be
 alive and waiting for the listener to get triggered. Just an idea though,
 the former option is much easier and should suit your current problem just
 fine.

 --- 
 --
 TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
 transit tracking app for Android-powered devices

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


Re: [android-developers] Re: interfacing to a server via http with a service

2011-02-07 Thread Kevin Duffey
Well Tre beat me to it. I was thinking two things. Either A, your main
activity registers a listener with another class that uses an AsyncTask in
it, and some sort of loop to repeatedly make the rest call. Then, when data
is returned, the response handler calls back via the listener and the main
activity updates the ui.

The other thought is some static method or class that is constructed with a
method in the main activity to call (perhaps via an interface
implementation?) and then response handler calls that method with new data,
which in turns updates the ui thread. I think the listener is the way to go
though.


On Mon, Feb 7, 2011 at 7:52 PM, Avtar Khalsa akhals...@gmail.com wrote:

 I do need the downloads to continue when the application switches
 activities, which is why I am using a service in the first place. It
 sounds like registering a listener is the way to go. Thank you so much
 for the help!

 On Feb 7, 10:34 pm, TreKing treking...@gmail.com wrote:
  On Mon, Feb 7, 2011 at 9:24 PM, Avtar Khalsa akhals...@gmail.com
 wrote:
   Thanks for the reply again. It was quite helpful. I am actually
 downloading
   small audio files for an answering machine app. If the activity that
   launched the service is still running, I would like it to update to
 include
   the newly downloaded files in the UI for the user to listen to. If the
 user
   has moved to a different activity, I just want the service to save the
 file
   to persistent storage. (It will store to persistent storage either way,
 but
   if the activity is running the UI should update) A service seems
 appropriate
   here although I am certainly open to other options?
 
  I guess it depends on the flow and user workflow of your app. If you
 start
  your app, it begins downloading, updates the UI as things becomes
 available,
  and then shuts down and stops the downloading when the user exist the
  Activity, then I would suggest an AsyncTask.
 
  If the user expects the downloads to continue and somehow play or be
  notified as they become available, then yeah, a Service seems more
  appropriate.
 
  Ultimately, either way will work.
 
   The issue I am having specifically is notifying the activity that the
   download is complete. I would really rather avoid having the activity
 poll
   the service to find out if the download is completed
 
  You've seen how most of the UI in Android works? Nearly everything
 registers
  a Listener object when it wants to know something happens. Create your
 own
  listener class like ServiceListener or something. Your service takes a
  reference and hold on to it. When a download is complete, it invokes the
  listener's onDownloadComplete() method (or whatever you want to call it).
 
  Meanwhile the Activity is the one that creates an instance of a custom
  listener and passes it to the service. When the service call it's method,
 it
  responds appropriately (updating the UI).
 
  You could also send a Broadcast that the Activity would register for,
 which
  would set you up for more advance functionality like background
 downloading
  and responding to downloading completing without needing your activity to
 be
  alive and waiting for the listener to get triggered. Just an idea though,
  the former option is much easier and should suit your current problem
 just
  fine.
 
 
 ---
 --
  TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
  transit tracking app for Android-powered devices

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


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