Can I run an Activity before running libgdx?

╄→尐↘猪︶ㄣ 提交于 2019-12-07 07:59:28

That's not going to work anyway, but I'd say it is likely crashing due to the StartActivity not being declared in the Manifest.

Yes, you can start an activity before running libgdx. Don't start the libgdx stuff first. Start the Bluetooth settings, then call the Intent to start the actual game when ready.

Like this:

public class BluetoothActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.bluetoothsettings);
        Button startGame = (Button)findViewById(R.id.btnStartGame);

        // handle set start click
        startGame.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(BluetoothActivity.this, GameActivity.class);
                BluetoothActivity.this.startActivity(intent);
            }
        });
    }
}

Then your game activity can just be the normal one that extends AndroidApplication like you have above.

And of course make sure your AndroidManifest.xml starts BluetoothActivity first, not libgdx.

<activity android:name=".BluetoothActivity">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!