在项目中定义一个服务,新建一个Service项目 New - Service - Service。
public class MyService extends Service {
public MyService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
}

Exported属性表示是否允许除了当前程序之外的其他程序访问这个服务,Enable属性表示是否启用这个服务。
Myservice继承自Service类,onBind方法也别醒目,这个方法是Service中唯一一个抽象方法,所以必须要在子类中实现
public class MyService extends Service {
public MyService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
&#