我的android工作室游戏有些问题。我不知道如何从游戏返回菜单。这是来自活动的代码。我无法从GamePanel获取任何信息,例如boolean:
public class Game extends Activity {
private boolean state= false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//turn off title
requestWindowFeature(Window.FEATURE_NO_TITLE);
// full screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
// usually shows xml activity_game
setContentView(R.layout.activity_game);
Button button = findViewById(R.id.button5);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//going to game loop
setContentView(new GamePanel(Game.this));
}
});
}
答案 0 :(得分:0)
使用CLEAR TASK和NEW TASK标志启动主菜单活动
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
我假设您知道如何开始和活动。如果你没有https://developer.android.com/guide/