Android Game Leader Board: Where to extends BaseGameActivity?

466 views Asked by At

My activity_main_layout has 2 buttons:

//Start game on click
<Button android:id="@+id/btnStart"/>

//If not sign in Google Game play Service
//Sign in then show leader board on click

<Button android:id="@+id/btnLeader board" />

Click on btnStart to begin playing game:

btnStart.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click
            Intent intent = new Intent(MainActivity.this, game_play.class);
            startActivity(intent);
            finish();
        }
    });

As you can see, class game_play is the place to play and update height score.

I'm wondering where to extends BaseGameActivity? Inside class MainActivity or game_play or both of them?

I try many times but it's not successfull.

I'm really an amateur, I expect that you give me some ideas.

1

There are 1 answers

0
Clayton Wilkinson On

Have you gone through the QuickStart Guide? This is a good place to start if you are new to developing games for Android. To answer you question, you need to access the Play Game Services from the activity that is going to handle signing in and calling game services APIs.

From your description it sounds like both your activities will need to make calls (the main activity is showing the leaderboard, and the game activity is most likely posting scores).

Extending your activity from BaseGameActivity really is not needed any longer (for an entertaining explanation watch: Death of BasegameActivity. What you do need to do is implement the two interfaces that handle initializing the GoogleAPIClient:

public class MainActivity extends Activity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { }

To implement these, refer to the samples and the doc: https://developers.google.com/games/services/android/init

You can do the same in your game activity. The application will maintain the login state between activities, so the player will not have to login twice.