LibGDX And​​roid的活动里LibGDX、And、roid

2023-09-04 08:34:27 作者:雾尽眉目清

我在开发一个小的应用程序为Android使用Android的UI和交互的大部分活动的中心,但一个关键的方面需要使用LibGDX(使用3D模型和物理)。我想可以点击我的应用程序(我的激活类),这将打开AndroidApplication级(我的泡泡龙类),初始化和运行所有LibGDX code按钮。

我的问题是,我不能使用意图,以启动一个AndroidApplication类(仅限一个活动,据我可以告诉)。我敢肯定,人们不得不解决这个问题,在过去,所以任何帮助将是非常美妙的。

下面是我的code到目前为止:

 公共类激活延伸活动{
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);

        尝试
        {
        的setContentView(R.layout.activate_screen);

        按钮b_Run =(按钮)findViewById(id.bActiveRun);

        b_Run.setOnClickListener(新View.OnClickListener(){
        @覆盖
        公共无效的onClick(视图v){
            意图to_Bobble =新的意图(v.getContext(),Bobble.class);
            startActivity(to_Bobble);
        }
    });
    }
    赶上(例外五)
    {
        Log.e(激活,在活动时出现错误,E);

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

}

 公共类泡泡龙扩展AndroidApplication {
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        生命周期循环=新的生命周期();
        loop.ddgSettings =新ddgSystemSettings(本);
        初始化(环,假);
    }
}
 

解决方案

好吧,我现在可以证实,没有任何问题,在所有与上述code。问题是,我没有宣布我的泡泡龙类/文件中的Andr​​oidManifest文件,以及导致运行时错误。

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);
    }
}

解决方案

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.