【发布时间】:2015-09-27 23:52:33
【问题描述】:
here是官方指南提供的代码,这是一个sn-p导致的问题。
@Override
public void onConnectionFailed(ConnectionResult result) {
if (mResolvingError) {
// Already attempting to resolve an error.
return;
} else if (result.hasResolution()) {
try {
mResolvingError = true;
result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
} catch (IntentSender.SendIntentException e) {
// There was an error with the resolution intent. Try again.
mGoogleApiClient.connect();
}
} else {
// Show dialog using GooglePlayServicesUtil.getErrorDialog()
mResolvingError = true;
GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this, REQUEST_RESOLVE_ERROR)
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
mResolvingError = false;
}
});
}
}
如果我在服务中使用它,当您读取作为参数传递给这些函数的变量 this 时,它们需要一个 Activity 类型。
我应该怎么做?这是一项服务。
出于同样的原因,我无法获得活动结果
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_RESOLVE_ERROR) {
mResolvingError = false;
if (resultCode == RESULT_OK) {
// Make sure the app is not already connected or attempting to connect
if (!mGoogleApiClient.isConnecting() &&
!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
}
}
}
【问题讨论】:
-
所以你的问题是获取一个 Activity 的引用??在服务的生命周期中,活动是否还活着?
-
什么类型的服务:启动、绑定、意图?
-
在活动可以处于任何状态时开始
标签: android arguments android-service google-play-services