I would like to implement Google Play Services in my android application, but I don't want application to ask user to sign in, when the applications starts for the first time, so I've used the following code in my Main Activity:
public class MainActivity extends BaseGameActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
if (prefs.getBoolean("pref_user_game_enabled", false) == false) {
getGameHelper().setMaxAutoSignInAttempts(0);
}
...
and I've implemented manual sign in, when user presses the button in the separate GameSignInActivity:
public class GameSignInActivity extends BaseGameActivity
implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
...
getGameHelper().setMaxAutoSignInAttempts(0);
findViewById(R.id.game_signin_btn_signin).setOnClickListener(this);
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.game_signin_btn_signin) {
getGameHelper().setMaxAutoSignInAttempts(3);
beginUserInitiatedSignIn();
}
else if (view.getId() == R.id.game_signin_btn_signout) {
signOut();
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
final Editor edit = prefs.edit();
edit.putBoolean("pref_user_game_enabled", false);
edit.commit();
}
}
@Override
public void onSignInSucceeded() {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
final Editor edit = prefs.edit();
edit.putBoolean("pref_user_game_enabled", true);
edit.commit();
}
Let's say user ran my app, signed in to Google Play, closed the app and now runs it again. How can I know that user is already signed before? isSignedIn() at MainActivity returns false. And what should I do to be able to use Google Play Services API there?