[英]Google auth in a service
我正在開發一種與活動進行通信並分散游戲流程的服務。
但是我的問題是,如果我通過服務調用它,那么當我調用mGoogleApiClient.connect()
時,如何顯示Google在活動中自動顯示的對話框?
這是我的服務班級:
public class MultiplayerService extends Service implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
public GoogleApiClient mGoogleApiClient;
@Override
public void onCreate() {
super.onCreate();
mBus.register(this);
initGoogleClient();
}
...
@Override
public void onConnected(@Nullable Bundle bundle) {
mEventPoster.postEventSafely(new BusEvent.UserLogged());
}
@Override
public void onConnectionSuspended(int i) {
mGoogleApiClient.connect();
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
mEventPoster.postEventSafely(new BusEvent.LogInFailed());
}
@Subscribe
public void onLogginClicked(BusEventActivity.LogInClicked event) {
mGoogleApiClient.connect();
mEventPoster.postEventSafely(new BusEvent.UserLogged());
}
...
可能嗎?
由於服務不是UI組件,因此無法顯示對話框。 他們也不能開始活動。
如果我通過服務調用mGoogleApiClient.connect(),如何顯示Google在活動中自動顯示的對話框?
不必擔心如何在服務中執行操作,而可以在活動上下文中正確執行操作。 有一些選擇。
可能還有更多的方法可以解決,但我想您知道這個想法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.