Im developing a service to communicate with the activities and fragments the game flow.
But my problem is, how can I show the dialogs that google automatically display in the activity when I call mGoogleApiClient.connect()
, if Im calling it over a service?
This is my service class:
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());
}
...
Is it possible?
答案 0 :(得分:1)
Services are not capable of showing dialogs, since they are not UI components. Neither can they start activities.
how can I show the dialogs that google automatically display in the activity when I call mGoogleApiClient.connect() , if Im calling it over a service?
Instead of worrying about how to do it in a service, do it properly, in the context an activity. There are some options.
There might be more ways to go about it, but I think you understand the idea.