LibGDX And​​roid的活动里 [英] LibGDX inside Android Activity

查看:123
本文介绍了LibGDX And​​roid的活动里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在开发一个小的应用程序为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.

这篇关于LibGDX And​​roid的活动里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆