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.
2 Answers
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.
-
\$\begingroup\$ Sounds easy enough, I don't have much experience creating callbacks I guess. Can you give me a simple example, or point me to a good resource? I think once I get this working I will have a lot of uses for it other than just database calls. Thanks! \$\endgroup\$ Feb 29, 2012 at 22:33
-
\$\begingroup\$ Yep, wait in a moment i put some classes :P \$\endgroup\$– Rudy_TMFeb 29, 2012 at 22:34
-
-
\$\begingroup\$ Thanks a lot! I understand what you mean now, you've been such a great help! There really should be some better documentation on this subject... \$\endgroup\$ Feb 29, 2012 at 22:57
-
If you want to use sqlite with libGdx you can use opensource project gdx-sqlite .
gdx-sqlite is a cross-platform Libgdx extension for SQLite database handling. The extension abstracts database handling to provide a unified method to handle database transacitons across multiple platforms while also adding SQLite support for desktop version of Libgdx application.