【发布时间】:2016-11-04 09:27:25
【问题描述】:
我有 2 个活动,活动 1 和活动 2。 在 Activity1->onCreate 我使用 googleApliClient 进行定位服务
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,我的问题是当我从 Activity1 移动到 Activity2 并再次回到 Activity1 时,它再次调用 onConnected 方法,我需要停下来
所以我尝试在 Activity1->onPause 上使用以下代码,但没有帮助。
@Override
protected void onPause() {
super.onPause();
mGoogleApiClient.disconnect();
}
【问题讨论】:
-
在 onCreate、onStart 或 onResume 中哪里创建
GoogleApiClient对象? -
请把onResume方法的代码...
-
1.GoogleApiClient对象在onCreate中初始化2.onResume方法不在activity中
标签: android google-api-client location-services