Fyi this approach is illustrated in the LocalService sample code.

On Sat, Apr 3, 2010 at 7:39 PM, JP <[email protected]> wrote:

> Kumar's method might work, but you should look up
> Context.bindService() and ServiceConnection.onServiceConnected()
> to find out how to do this within Android's framework.
>
> What I do: In MyApplication's
>    @Override public void onStart()
> I call:
> bindService(new Intent(MyApplication.this, MyService.class),
>    new (MyServiceConnection(this)),
>    BIND_AUTO_CREATE);
>
> MyServiceConnection implements ServiceConnection, and as soon as the
> service is created or bound, you get a call to
> MyServiceConnection.onServiceConnected(), which you implement like
> this:
> public void onServiceConnected(ComponentName name, IBinder service) {
>    serv = ((MyService.LocalBinder)service).getService();
> }
> With serv being an instance variable of MyApplication of type
> MyService which you can use to call methods of your Service. Hope this
> helps.
>
>
>
> On Mar 30, 1:26 am, T-Droid <[email protected]> wrote:
> > Hi @all,
> >
> > I have a design problem with my Android components.
> >
> > My activity is starting a service which is doing the work in the
> > background. What I want is that the service informs the activity about
> > state changes. How can I do this?
> >
> > Normally I would add an observer but the activity has no reference to
> > the service. Then I was thinking to take AIDL but this is more for
> > inter-process communication.
> >
> > How is it possible that the service informs the activity about state
> > changes? Both are running in the same process. What can you recommend?
> >
> > Thank you in advance.
> >
> > T-Droid
>
> --
> 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]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
> To unsubscribe, reply using "remove me" as the subject.
>



-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

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