无法将JobService的context参数传递给类

问题描述 投票:0回答:1

我无法将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和服务是其背景。

java android android-context
1个回答
0
投票

从构造函数中删除void

你的构造函数应该是这样的

public Mylocation(Context context){
        this.context=context;
    }
© www.soinside.com 2019 - 2024. All rights reserved.