Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I want to know if I can just implement sqlite database for android in libgdx game? Also if this is not possible then may I know the simple way to integrate libgdx game to just store scores in sqlite database. I dont want to use preference or jason because I have to get last stored scores and then level wise comparison of scores.

share|improve this question

closed as too broad by Josh Petrie Dec 22 '14 at 18:51

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs. If this question can be reworded to fit the rules in the help center, please edit the question.

    
Questions asking "is it possible" are yes-or-no questions, which are generally poor questions for the SE format. The implicit follow up ("how can I...") is too broad with the limited information you've provided and probably isn't particularly game-development specific anyway (so should be asked on SO). –  Josh Petrie Dec 22 '14 at 18:52
    
Ók. I am new here so I was not knowing how to ask. Thank you for pointing out my mistakes. –  Aiman Batul Dec 23 '14 at 4:19

1 Answer 1

up vote 0 down vote accepted

To use platform specific code in libgdx you make an interface in your core project.


interface SaveScore {
   public void saveScore(int score);
}

And then make an implementation in your android project and any other projects you might have (desktop, ios and so on).


public class SaveScoreAndroid implements SaveScore {
    public void saveScore(int score) {
        //Platform specific code goes here
    }
}

Then you make your application listener take in an implementation of the interface as an argument in the constructor. Now you can pass in the platform specific implementation of the interface in the starter class of your android project.

protected void onCreate (Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
    initialize(new MyGame(new SaveScoreAndroid()), config);
}
share|improve this answer
    
I have accepted this answer. As I will try doing it this way. Thank you. –  Aiman Batul Dec 23 '14 at 4:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.