尝试将您的活动更改为如下所示。其他一切(例如RequestHandler)都应该是正确的。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initialize(new ConfirmTest(this), false);
}
@Override
public void confirm(final ConfirmInterface confirmInterface) {
runOnUiThread(new Runnable(){
@Override
public void run() {
new AlertDialog.Builder(ConfirmTestAndroidActivity.this)
.setTitle("Confirm")
.setMessage("Are you sure?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
confirmInterface.yes();
dialog.cancel();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
})
.create().show();
}
});
}
要使用自定义配置,您可以使用:
Game myGame = new Game(); // your game class which implements ApplicationListener
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
cfg.useGL20 = true;
cfg.useCompass = false;
cfg.useAccelerometer = false;
cfg.useWakelock = true;
cfg.touchSleepTime = 16;
initialize(myGame, cfg);
请记住,使用 WakeLock 功能需要声明 AndroidManifest.xml 中的权限,否则将引发 SecurityException。
<uses-permission android:name="android.permission.WAKE_LOCK" />