LibGDX inside Android Activity

陌路散爱 提交于 2019-11-27 17:52:22

问题


I'm in the middle of developing a small app for Android using the Android UI and activities for the most part of the interaction, however one key aspect requires the use of LibGDX (using 3D models and physics). I want to be able to click a button in my app (my "Activate" class) which will open the "AndroidApplication" class (my "Bobble" class) that initializes and runs all the LibGDX code.

My problem is that I can't use an "Intent" to start an AndroidApplication class (only an Activity as far as I can tell). I'm sure that people have had to work around this issue in the past so any help would be fantastic.

Here's my code so far:

public class Activate extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        try
        {
        setContentView(R.layout.activate_screen);

        Button b_Run = (Button) findViewById(id.bActiveRun);

        b_Run.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent to_Bobble = new Intent(v.getContext(), Bobble.class);
            startActivity(to_Bobble);
        }
    });
    }
    catch (Exception e) 
    {
        Log.e("Activate", "Error in activity", e);

        Toast.makeText(getApplicationContext(), 
                        e.getClass().getName() + " " + e.getMessage(), 
                        Toast.LENGTH_LONG).show();
    }
}

}

public class Bobble extends AndroidApplication {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LifeCycle loop = new LifeCycle();
        loop.ddgSettings = new ddgSystemSettings(this);
        initialize(loop, false);
    }
}

回答1:


Ok I can now confirm that there is no issue at all with the above code. The issue was that I hadn't declared my "Bobble" class/file in the AndroidManifest file, and that was causing the runtime error.



来源:https://stackoverflow.com/questions/10711995/libgdx-inside-android-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!