我无法将JobService的上下文传递给位置提供程序类。这是我试过的:
我的位置提供者类:
public class Mylocation implements
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
LocationListener {
private Context context;
public void Mylocation(Context context){
this.context=context;
}
//other methods of Location provider
}
这是我的JobService:
public class LocationMonitoringService extends JobService {
Mylocation mylocation=new Mylocation(this);
//blah blah
}
当我写Mylocation(this)
时,我在this
上得到错误。实际上我想将JobService的上下文传递给类。这是我在Android Studio中遇到的错误:
Mylocation中的Mylocation()不能应用于com.example.app.JobService
据我所知,JobService
扩展service
和服务是其背景。
从构造函数中删除void
你的构造函数应该是这样的
public Mylocation(Context context){
this.context=context;
}