Thanks for that! Excellent code.

But I have a problem!

When I try to do the following:

 private MyService service=null;

         private ServiceConnection svcConn=new ServiceConnection() {
             public void onServiceConnected(ComponentName className,
             IBinder binder) {
             service=(MyService)binder;

             try {
             service.getRingTone();
             }
             catch (Throwable t) {
             Log.e("Patchy", "Exception in call to registerAccount()", t);
             //goBlooey(t);
             }
             }

             public void onServiceDisconnected(ComponentName className) {
             service=null;
             }
             };


bindService(new Intent(this, MyService.class), svcConn,
                        BIND_AUTO_CREATE);

I get an uncaught exception error on this line:

service=(MyService)binder;

09-13 10:06:53.566: ERROR/AndroidRuntime(18791): Uncaught handler: thread
main exiting due to uncaught exception
09-13 10:06:53.676: ERROR/AndroidRuntime(18791):
java.lang.ClassCastException: com.xxx.phone.MyService$1
09-13 10:06:53.676: ERROR/AndroidRuntime(18791):     at
com.xxx.phone.ui.MyActivity$2.onServiceConnected(MyActivity.java:515)

So it doesn't like the cast from binder to Service?

How can I fix that do you know? What am I missing from the example?




On Sat, Sep 11, 2010 at 8:22 AM, Federico Paolinelli <[email protected]>wrote:

> You need to use aidl if you want to call another process. But if you
> want to interact with the service from activities of the same
> application,
> you can call the methods directly from the activity.
>
> Check for example this sample code from Mark's tutorial:
> http://github.com/commonsguy/cw-andtutorials/tree/master/18-LocalService/
>
>
>
> On 10 Set, 19:32, Donal Rafferty <[email protected]> wrote:
> > As in the following piece of code...? :
> >
> > bindService(bindIntent, mConnection, Context.BIND_AUTO_CREATE);
> >
> > I do that but I think I do require the aidl to be able to call methods
> from
> > the service?
> >
> > On Fri, Sep 10, 2010 at 6:17 PM, Federico Paolinelli <[email protected]
> >wrote:
> >
> > > In any case, I meant binding the activity to the service using
> > > bindService method without passing from the aidl.
> > > In this way you will get direct access to the methods of the service
> > > directly from the activity. In this way, I suppose you can pass the
> > > service an interface to get called when your asynctask finished its
> > > job.
> >
> > > Try to google for service binding examples.
> >
> > > Hope this helps (and I hope I am not saying bullshit as well :-) )
> >
> > >    Federico
> >
> > > On Fri, Sep 10, 2010 at 7:03 PM, Donal Rafferty <[email protected]>
> wrote:
> > > > No luck :(
> >
> > > > ---
> >
> > > > package com.xxx.phone.ui;
> >
> > > > import android.media.Ringtone;
> >
> > > > interface ICallDialogActivity{
> > > >     void sendRingTone(in RingTone aRingTone);
> > > > }
> >
> > > > ---
> >
> > > > I get the red x beside the import and "coundn't find import for class
> > > > android.media.Ringtone;"
> >
> > > > On Fri, Sep 10, 2010 at 5:45 PM, Mark Murphy <
> [email protected]>
> > > > wrote:
> >
> > > >> On Fri, Sep 10, 2010 at 12:28 PM, Donal Rafferty <[email protected]
> >
> > > >> wrote:
> > > >> > Is that possible?
> >
> > > >> > I have a bind between my Service and the Activity at the minute
> but
> > > when
> > > >> > I
> > > >> > try to change to aidl file to allow me pass the RingTone object it
> > > wont
> > > >> > compile for me, saying RingTone and com.android.RingTone cannot be
> > > >> > resolved/found
> >
> > > >> Try android.media.Ringtone.
> >
> > > >> --
> > > >> Mark Murphy (a Commons Guy)
> > > >>http://commonsware.com|http://github.com/commonsguy
> > > >>http://commonsware.com/blog|http://twitter.com/commonsguy<http://commonsware.com/blog%7Chttp://twitter.com/commonsguy>
> >
> > > >> Android Training in London:
> http://skillsmatter.com/go/os-mobile-server
> >
> > > >> --
> > > >> 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]>
> <android-developers%[email protected]<android-developers%[email protected]>
> >
> > > >> 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
> [email protected]
> > > > To unsubscribe from this group, send email to
> > > > [email protected]<android-developers%[email protected]>
> <android-developers%[email protected]<android-developers%[email protected]>
> >
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/android-developers?hl=en
> >
> > > --
> > > --------
> > > Federico
> >
> > > --
> > > 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]>
> <android-developers%[email protected]<android-developers%[email protected]>
> >
> > > 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 [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
>

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