Hi,

I solved the problem as spachner mentioned. From my point of view it
was easy to understand.

About the second solution I still get not the whole idea. If I have a
connection between the service and the activity. How do they
communicate? Is there an interface between them?

@Dianne: Thanks to point out to the sample code. I think I got the
idea of binding them together. How do the service send an event to the
activity?
>From the service is there a possibility to invoke the activity like
mMyActivity.changeState();.

Another point which I was recognizing you are talking about how a
activity knows the service. I'm talking how a service knows an
activity. Because in my design the service should trigger view
changes. The communication is unidirectional.

Thanks in advance
T-Droid

On Apr 4, 8:24 am, Dianne Hackborn <[email protected]> wrote:
> 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