![](/img/trans.png)
[英]How can I make sure that my ArrayList is filled in the OnCreate Method before being called in OnMapReady?
[英]How do I make sure that it is connected() before any method is invoked? My methods are beight called AFTER the GooglePlus authentication
请查看以下LogCat输出。 在Base.OnStart()中,我正在调用mPlusClient.connect();。 现在,我正在ShowLog.OnStart中调用各种方法,但是仅仅因为Google尚未通过身份验证,它会引发错误“ GoogleApiClient未连接”。
我应该怎么做才能更改设计,以使其始终保持连接,然后只有我调用各种方法。
mainActivity.onCreateOptionsMenu called
Base.onConnectionFailed called
onClick called
onActivityResult called
Base: onConnected called. Is Google connected?true
showLog: onCreate
Base: onCreate
showLog: onCreate: is Google connected?false
showLog: onStart
Base: onStart
Base: onStart. Is Google connected?false
**showLog: onStart: is Google connected?false**
showLogsActivity.onCreateOptionsMenu called
Base: onConnected called. Is Google connected? **true**
Base: onStop
showLog: onStop
Base: onStop
我还将包括以下代码(为了使内容简洁,我正在删除一些代码)。 这是完整的代码: http : //codeviewer.org/view/code : 52b6
感谢编辑1 *建议后,我将代码修改为:
Class showLog{
@Override
void onGooglePlayServicesConnected() {
if (mPlusClient.isConnected()) {
//background process to get Picasa Photo
AsynTaskGetPicasaMedia objAsyncTaskGetPicasaMedia = new AsynTaskGetPicasaMedia(getApplicationContext());
objAsyncTaskGetPicasaMedia.execute();
}
}
}
现在在类AsynTaskGetPicasaMedia中
@Override
protected Boolean doInBackground(Void... params) {
final String accountName = Plus.AccountApi.getAccountName(BaseActivity.mPlusClient);
}
我仍然遇到错误!
如果您的基类实现了对Google Play服务的回调,那么您将在该基类中创建一个在连接时调用的方法。
例
@Override
public void onConnected(Bundle connectionHint) {
onGooglePlayServicesConnected();
}
public void onGooglePlayServicesConnected(){
}
在扩展此基类的活动中,只需重写onGooglePlayServicesConnected()
方法
@Override
public void onGooglePlayServicesConnected() {
//do stuff here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.