Hello. To turn from scene to android classes - I used interfaces. But how to turn from the android class to the scene? For example, when you press a button on the scene, a request is made for a method in the Android project, it counts something and after that I need to open a drp scene, for example, how is this possible?

As for the return answers, let's not, it works, but I need to open the scene from the android project. Thank.

    1 answer 1

    You can make the following system of events. There is a special object with the Dispatch method, which we will later redefine:

     public class EventObject implements EventObject { @Override public void Dispatch(Object data) { } } 

    Add a class that implements the registration system for such objects associated with the EventType events that EventType :

     public abstract class AbstractStream { public enum EventType {}; private ListMultimap<Object, EventObject> listeners = ArrayListMultimap.create(); public void addListener(EventObject listener, Object eventType){ listeners.put(eventType, listener); } public void removeListener(EventObject listener, Object eventType){ listeners.remove(eventType, listener); } public void callEvent(Object eventType, Object data) { for (EventObject hl : listeners.get(eventType)) hl.Dispatch(data); } } public class RealStream extends AbstractStream { public enum EventType { SomethingHappens } } 

    Now it’s enough to subscribe to the SomethingHappened event in the class in which you need to call the method:

     public class TestClass implements MyActivatedController { private EventObject dispatchObject; public TestClass() { dispatchObject = new EventObject() { @Override public void Dispatch(Object data) { TestMethod(data); } }; } public void Activate() { SomethingStatic.RealStream.addListener(dispatchObject, RealStream.EventType.SomethingHappens); } public void Deactivate() { SomethingStatic.RealStream.removeListener(dispatchObject, RealStream.EventType.SomethingHappens); } public void TestMethod(Object data) { Gdx.app.log("TestMethod", (String)data)); } } 

    It remains only to call the callEvent method callEvent

     SomethingStatic.RealStream.callEvent( SomethingStatic.RealStream.EventType.SomethingHappens, "Test data"); 

    which leads to a call to TestMethod with the parameter we set.