我正在尝试进行首次服务。我获得的示例代码在创建服务的活动中将ServiceConnection创建为内部类。
我希望ServiceConnection在创建服务的活动类之外,以便其他actite可以创建该服务并使用相同的ServiceConnection类。
因此,我正在尝试对其进行子类化,以便将其创建在其自己的文件中。
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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3419 次 |
| 最近记录: |