Tuesday, October 11, 2016

android - SQLite in libGDX


Does anyone have an example of how I can use SQLite in libGDX? I have a class in my original Android code that allowed me to easily access a database but I can't seem to find anything equivalent to that in libGDX. Or maybe I am missing something? Am I able to use that in the libGDX code somehow? Sorry I am new to libGDX.



Answer



If you have that, you can use (callbacks).



You define an interface, and implement the methods in the android classes, in that way you can retrieve data and get it in your libGdx project.


Its an easy way.


public interface ActionPerformed 
{
public String actionPerformed();
}


public class AppActivity extends AndroidApplication implements ActionPerformed
{


public AppActivity()
{
new XMLProgress(this);
}

public String actionPerfomed()
{
//Here goes your code;
}

}

public class XMLProgress
{
static ActionPerformed action;

public XMLProgress(ActionPerformed a)
{
action = a;
}


public String getMethod()
{
return action.actionPerformed();
}
}

I used my class in libgdx as a singleton, because i dont need a lot of instances, and i secure that is always live.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...