报错内容 Error:(55, 15) 错误: 从内部类中访问本地变量service2; 需要被声明为最终类型
//下面是主要代码内容
//报错内容 Error:(55, 15) 错误: 从内部类中访问本地变量service2; 需要被声明为最终类型
MyBindService service2;
ServiceConnection conn1=new ServiceConnection() {
@Override//启动源跟service连接成功后自动调用
public void onServiceConnected(ComponentName name, IBinder binder1) {
service2= ((MyBindService.MyBinder)binder1).getService1();
}
@Override//启动源跟service的连接以为丢失的时候会调用这个方法,例如崩溃 呗杀死
public void onServiceDisconnected(ComponentName name) {
}
};//下面是Mybindservice.java类的内容
package com.example.administrator.myapplication;
import android.app.Service;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
/**
* Created by Administrator on 2015/5/5.
*/
public class MyBindService extends Service {
@Override
public void onCreate() {
Log.i("info", "**********IBinder onBind");
super.onCreate();
}
public class MyBinder extends Binder{
public MyBindService getService1(){
return MyBindService.this;//返回服务对象
}
}
@Override
public IBinder onBind(Intent intent) {
Log.i("info", "**********IBinder onBind");
return new MyBinder();
}
@Override
public void unbindService(ServiceConnection conn) {
Log.i("info", "**********IBinder onBind");
super.unbindService(conn);
}
public void play1(){
Log.i("info", "**********IBinder 播放");
}
public void stop1(){
Log.i("info", "**********IBinder 停止");
}
}
