传递给isGooglePlayServicesAvailable(Context context)方法的正确上下文是什么?
发布于 2014-07-16 18:31:30
您可以传递任何上下文,例如:
this),getApplicationContext()),getBaseContext())等。实际上,isGooglePlayServicesAvailable()附加到整个应用程序中,而不是一个活动,这就是为什么您可以使用任何上下文对象的原因。
希望这些信息能对你有所帮助。
发布于 2014-07-16 18:31:11
当用户启动我的应用程序时,我只使用用户登陆的活动上下文,这是有效的(我们已经在这里的测试中显示了它)。
我在这个活动中的代码是:
private void checkPlayServices() {
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (status != ConnectionResult.SUCCESS) {
if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
GooglePlayServicesUtil.getErrorDialog(status, this, 0).show();
} else {
ToastHelper.showCenteredToast("Until you update your Google Play Services, this app cannot run on this phone");
finish();
}
}您可以在函数的第一行中看到,我将this传递到检查中,它只是映射到一个Activity。
https://stackoverflow.com/questions/24788007
复制相似问题