Reputation: 326
I created an application based on the library libgdx. As a result, I got a few projects (android, html, ios, desctop, and core). The final program is written for Android. How do I call a method from the Android project, for example, when I click on actor will be called the method who writes anything in the database or writes something in log.
Android project: Example
public class AndroidLauncher extends AndroidApplication {
/*example method*/
public void LogU()
{
Log.e("im there","yea");
}
}
}
Core project:
public class GameHostScreen implements Screen {
class GoToMenuListener extends ClickListener
{
@Override
public void clicked(InputEvent event, float x, float y) {
//need to call LogU() here
}
}
}
Sry for my bad english
Upvotes: 1
Views: 1562
Reputation: 1061
I think it's the best answer: Creating callback
As an example Create an interface in the core project
public interface IMainActivity {
void showMainPanel();
void showScorePanel(int score);
void hideUi();
}
Then implement your activity with that interface and call that interface from your core project
In android project:
public class MainActivity extends AndroidApplication implements IMainActivity
In core project:
private IMainActivity context;
public DoodleJump(IMainActivity context) {
this.context = context;
}
Upvotes: 1