我有2个Activity1和Activity2活动。 上Activity1->的onCreate我用googleApliClient位置服务如何在活动恢复时停止拨打onConnected(Android)
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
@Override
public void onConnected(@Nullable Bundle bundle) {
createLocationRequest();
}
其做工精细,并呼吁onConnected适当的,我的问题是,当我移动到活性2从活动1,再回来到活动1,它再次调用onConnected方法,我需要停止
所以我尝试使用Activity1-> onPause上的以下代码,但它没有帮助。
@Override
protected void onPause() {
super.onPause();
mGoogleApiClient.disconnect();
}
凡的onCreate,在onStart或创建的onResume'GoogleApiClient'对象? –
请将onResume方法的代码... –
1.GoogleApiClient对象在onCreate中初始化 2.onResume方法不在活动内 –