0
我将跟踪服务背景以及MainActivity放在同一个包中时我没有收到任何错误,但是当我试图在不同的包中分离它们时(trackingService - com.bustracker.trackingService)和(MainActivity in com.bustracker.monitoring)然后我在这条线mService = binder.getService();
下面的错误The method getService() from the type TrackingService.LocalBinder is not visible
TrackingService.LocalBinder类型的方法getService()不可见
我该如何解决它?
MainActivity:
package com.bustracker.monitoring;
public class MainActivity extends ActionBarActivity implements
AsyncTaskCallback {
TrackingService mService;
TrackingService mService;
boolean mBound = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.route_available);
// Start the TrackingService class.
Intent i = new Intent(this, TrackingService.class);
startService(i);
getAvialableRoutes();
System.out.println("ABC MainActivity onCreate() ");
}
private ServiceConnection mConnection = new ServiceConnection(){
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
System.out.println("ABC MainActivity onServiceConnected()");
// We've bound to LocalService, cast the IBinder and get LocalService instance
LocalBinder binder = (LocalBinder) service;
//Here I am getting the error "The method getService() from the type TrackingService.LocalBinder is not visible"
mService = binder.getService();
mBound = true;
}
@Override
public void onServiceDisconnected(ComponentName name) {
System.out.println("ABC MainActivity onServiceDisconnected()");
mBound = false;
}
};
}
TrackingService:
package com.bustracker.trackingService;
public class TrackingService extends Service implements AsyncTaskCallback,
LocationListener {
private final IBinder mBinder = new LocalBinder();
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
detectLocation();
return START_NOT_STICKY;
}
public class LocalBinder extends Binder {
TrackingService getService() {
// Return this instance of TrackingService so clients can call public methods
return TrackingService.this;
}
}
}