Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a "no interface expected here" when I try to subclass ServiceConnection [duplicate]

Tags:

java

android

I'm trying to make my first service. The sample code I got has the ServiceConnection created as a inner class in the activity that creates the service.

I would like ServiceConnection to be outside the activity class that creates the service so other actites can crat the service and use the same ServiceConnection class.

So i'm trying to sublclass it so it will be created in its own file.

public class CMYServiceConnection extends ServiceConnection {
                                    I GET ERROR HERE

Messenger mService = null;
boolean mBound;


public void onServiceConnected(ComponentName className, IBinder service) {
    // This is called when the connection with the service has been
    // established, giving us the object we can use to
    // interact with the service.  We are communicating with the
    // service using a Messenger, so here we get a client-side
    // representation of that from the raw IBinder object.
    mService = new Messenger(service);
    mBound = true;
}

public void onServiceDisconnected(ComponentName className) {
    // This is called when the connection with the service has been
    // unexpectedly disconnected -- that is, its process crashed.
    mService = null;
    mBound = false;
}

}
like image 325
Ted pottel Avatar asked Dec 03 '22 20:12

Ted pottel


1 Answers

ServiceConnection is an interface, and classes can't extend interfaces.

Use implements instead

like image 104
Zoe stands with Ukraine Avatar answered Dec 06 '22 09:12

Zoe stands with Ukraine