8

Recently I've added Google Play Game Services support in my app (added BaseGameActivity and GameHelper), and it sign-in and sign-out workflow worked fine. In my graphics thread I send message to main activity handler, it calls beginUserInitiatedSignIn or signOut. When identification process completes Game Helper calls onSignInFailed or onSignInSucceeded of my activity and I can check isSignedIn (true if onSignInSucceeded was called).

But today I've found that it behaves strange now. Sadly that I did not backup last working version, but the essense code is the same.

If I ask app to sign in it shows google services sign-in dialog (I have 2 accounts on my device). I choose an account, press ok, it returns to my app but neither onSignInSucceeded nor onSignInFailed is called (previously if I canceled this dialog I saw "unknown error" message). When I try to sign in in the second time it launches a rotating circle and waits endlessly. If I tap on screen it aborts waiting and returns to my view.

ALTHOUGH if I close the app and launch it once again, it signs in on launch successfully, call onSignSucceded and stay connected when I check in runtime. It says:

onCreate: creating GamesClient
onStart.
onStart: connecting clients.
Connecting GamesClient.
onConnected: connected! client=1
All clients now connected. Sign-in successful.
All requested clients connected. Sign-in succeeded!

If I sign out and then try to sign in again, it shows accounts dialog and writes:

isGooglePlayServicesAvailable returned 0
beginUserInitiatedSignIn: starting new sign-in flow.
Connecting GamesClient.
onConnectionFailed: result 4
onConnectionFailed: since user initiated sign-in, trying to resolve problem.
resolveConnectionResult: trying to resolve result: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{41f8a610: android.os.BinderProxy@41f8a5b0}}
result has resolution. Starting it.

When I choose an account it returns to my activity and neither onSignInSucceeded nor onSignInFailed is called. If I check in runtime I see that app is not connected to google services. When I try to sign in again it shows forever rotating circle and says:

isGooglePlayServicesAvailable returned 0
beginUserInitiatedSignIn: continuing pending sign-in flow.
resolveConnectionResult: trying to resolve result: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{41f8a610: android.os.BinderProxy@41f8a5b0}}
result has resolution. Starting it. 

When I tap the screen, circle is aborted without calls to onSignInSucceeded nor onSignInFailed and so on.

I can't imagine what went wrong. Handler is created on main thread. I have Google example, and it signs in and signs out without any problem, just like my app did. Can somebody tell what can be wrong? Thanks!

Tertium
  • 6,049
  • 3
  • 30
  • 51
  • Maybe you need to share some code! – thiagolr May 29 '13 at 11:30
  • Actually I don't know what code to share... Everything is as always. My activity is descedant of BaseGameActivity from Google. I call on main thread these two methods (beginUserInitiatedSignIn or signOut) and expect callbacks onSignInSucceeded or onSignInFailed. I thought if someone faced with similar symptoms they can suggest what's wrong. Maybe something happened to server setup. But it worked before... – Tertium May 29 '13 at 21:02

1 Answers1

25

It took 2 days to find a silly mistake. When you extend BaseGameActivity make sure you call all its methods in your activity methods (if you override them), for example:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
 super.onActivityResult(requestCode, resultCode, data);
 ....
 <our code here>
}

BaseGameActivity calls its aggregated mHelper's methods which do all the magic.

Tertium
  • 6,049
  • 3
  • 30
  • 51
  • 1
    Wow this was the exact solution I needed. I added onActivityResult but tested it before adding the code I needed (including super.onActivityResult). Thanks for posting your solution!!! – easycheese Jun 02 '13 at 14:06
  • You're a life saver ! I'll give you +100 reputation in 23 hours ! – Stephane Mathis Jun 03 '13 at 20:38
  • Since this moment in life I moved to mercurial. If only I commit every day - I could see what was changed, but with svn I had to beware and work in offline (I've gone through svn branch merge nightmare couple of times :) ) – Tertium Jun 04 '13 at 17:15
  • YOU. ARE. DA. MAN. THANK YOU! – async Apr 04 '14 at 20:12
  • Nice find! I'm having the exact same problem, I forgot to call `super()` from `onActivityResult()`. Thanks for posting your solution, it saved me a lot of time. – Daniel May 30 '14 at 17:41