![](/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.