Pass ArrayList from android module to kernel in libgdx

I am using libgdx. I need to pass an ArrayList from TaskSet from android to the kernel. The problem is that TaskSet is in android module. I can pass some standard objects, such as Strings, this way:

public class DragAndDropTest extends ApplicationAdapter {
......
    public DragAndDropTest(String value){
        this.value=value;
    }
......
}

In AndroidLauncher:

AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
                LinearLayout lg=(LinearLayout) findViewById(R.id.game);
                lg.addView(initializeForView(new DragAndDropTest("Some String"), config));

It works fine, but I need to pass ArrayList from TaskSet, TaskSet is in android module

I know that a bad solution is to place the TaskSet in the "main" module, but in any case I need some methods to transfer the wigh android part

+4
source share
1 answer

, , . , . Android APK .

, android core build.gradle. :

project(":core") {
    apply plugin: "java"
    apply plugin: "android"

    configurations { natives }

    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"        
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
    }
}

, , , , , . , , TaskSets, Android. - :

public interface PlatformResolver {
    public void handleTasks();
}

-

public class MyGame extends ApplicationAdapter {
    //......

    PlatformResolver platformResolver;

    public MyGame (PlatformResolver platformResolver){
        this.platformResolver = platformResolver;
    }

    //.....
    public void render(){
        //...

        if (shouldHandleTasks) platformResolver.handleTasks();

        //...
}

-

public class AndroidLauncher extends AndroidApplication implements PlatformResolver {

    public void handleTasks(){
        //Do stuff with TaskSets
    }

    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        someDataType SomeData;

        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        // config stuff
        initialize(new MyGame(this), config);
    }

}

-

public class DesktopLauncher  implements PlatformResolver{

    public void handleTasks(){
        Gdx.app.log("Desktop", "Would handle tasks now.");
    } 

    public static void main (String[] arg) {
        LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
        config.title = "My GDX Game";
        config.width = 480;
        config.height = 800;
        new LwjglApplication(new MyGame(this), config);
    }
}
+2

All Articles