0

I am trying to implement an online leaderboard for the newest version of my app. I followed the tutorial found here:

http://swarmconnect.com/admin/docs/leaderboard

Here is relevant code from MainMenu.java.

public void onCreate(Bundle savedInstanceState) {

    // if user has logged in before, automatically login user without showing the home screen
    if(Swarm.isEnabled()) {
        autoLogin();
    } else {
        login();
    }

    if(Swarm.isEnabled() == false) {
        autoLogin();
    }

}

public void autoLogin() {
    Swarm.init(MainMenu.this, ...., "...");
}

public void login() {

            Swarm.init(MainMenu.this, ..., "...");
        }
}

Results.java displays after the quiz is over. Here is the relevant code in there:

public void submitScore(long score) {
    SwarmLeaderboard.submitScore(LEADERBOARD_ID, score);
}

Here is relevant code from Highscores.java:

public void showLeaderboard() {
    SwarmLeaderboard.showLeaderboard(LEADERBOARD_ID);
}

That is all the code I have and that is all that was on the SwarmConnect website. I am able to login from the MainMenu successfully and the app never crashes. But when I go to Highscores.java nothing is displayed. There has to be more code but I don't see any docs anywhere for instructions past the ones in the link at the top.

My question is how to display the scores that were submitted from the Results.java page.

Matt
  • 3,882
  • 14
  • 46
  • 89

2 Answers2

1

Okay, I have SwarmConnect on a simple game I made.

Here's the code I used to show LeaderBoards: Swarm.showLeaderboards(); It was Swarm and not SwarmLeaderboard.

halfer
  • 19,824
  • 17
  • 99
  • 186
Karthik Balakrishnan
  • 4,353
  • 6
  • 37
  • 69
0

Please make sure you've followed the Swarm setup docs (http://swarmconnect.com/admin/docs/setup). Particularly the section for extending SwarmActivity (or alternatively, calling setActive() and setInactive()). My guess is that Swarm doesn't have an active Context to work with, and thus won't display new screens.

impact
  • 396
  • 2
  • 6
  • As for the link, I have already been through and completed all 5 steps into all my code before posting my opening post. As for the part of your comment about Context, that might be it. If you look in my code above, nowhere is a Context variable used. But the reason is because the SwarmConnect docs didn't have it in there if I remember correctly. I should add that the login screen does appear on my `MainMenu` and I am able to successfully login. It is just the leaderboard that never appears. – Matt Apr 09 '13 at 02:12
  • 1
    The way Swarm handles Contexts, is if it takes over the screen (Login screen for example), it sets itself as Active (Swarm.setActive()). When it gives up it's ownership of the screen (back to your game), it calls setInactive() with its activity, and expects you to call setActive() with your activity (when you get your onResume()), so that Swarm knows that your application is still active, and hasn't quit entirely. If you try to call showLeaderboard(), or something else, and missed a setActive(), Swarm thinks your app is in the background, and tries to avoid taking over the screen. – impact Apr 09 '13 at 22:10