Android 未执行LocationClient的回调参数
我在非活动类中有这个函数Android 未执行LocationClient的回调参数,android,google-maps,Android,Google Maps,我在非活动类中有这个函数 public class MapClass extends Activity implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener, OnItemSelectedListener { ... protected boolean initiateMap(Context mainAppContext, MapFr
public class MapClass extends Activity implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener, OnItemSelectedListener { ...
protected boolean initiateMap(Context mainAppContext, MapFragment mapFrag) {
….
mLocationClient = new LocationClient(mainAppContext, this, this);
mLocationClient.connect();
…
}
我从mainactivity调用此函数,并将其上下文mainAppContext
作为对象传递给func
我的问题是LocationClient
的最后两个参数实际上是回调
虽然我在同一个非活动类中定义了它们:
@Override
public void onConnected(Bundle arg0) {
gotoCurrentLocation();
}
@Override
public void onDisconnected() {
Toast.makeText(this, R.string.onDisconnected, Toast.LENGTH_LONG).show();
}
但是他们从来没有因为成功的连接而被呼叫过?在本例中,这个
似乎没有按我所希望的那样工作(实际上我是在教程中看到的)
有人能帮我把这两个回调作为参数传递给
LocationClient
构造函数吗?您的onConnectionFailed
是否被调用?你从哪里得到你的背景?如果您在活动中,您应该使用此
,因为contextmyConnection正在获得成功,所以onConnectionFailed
不会以任何方式执行。我正在传递主活动的上下文。我以为您说过OnConnect没有被调用?是的OnConnect
没有被调用,但连接成功,因此onConnectionFailed
无论如何都不会被调用。您如何知道连接成功?这可能是您的上下文,您应该使用此
作为上下文,而不是其他活动