[英]How can I jump from activity B to A more than just once
I have two layouts, A and B. The app launches the A_layout, and through a button you can go to the B_layout. 我有两种布局,A和B。该应用程序启动A_layout,然后通过按钮可以转到B_layout。 On default when you press the back button the app closes, doesnt matter if the app is on the A or B layout.
默认情况下,当您按下“后退”按钮时,应用程序关闭,无论应用程序是在A布局还是B布局上都没有关系。 When I override the back button to set the content view always on the layout A whenever the back button is pressed, then I cant open the B activity anymore through the button.
当我按下后退按钮以始终在布局A上设置内容视图时,无论何时按下后退按钮,我都无法再通过该按钮打开B活动。 How do I need to override the method correctly?
我该如何正确覆盖该方法? :)
:)
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
setContentView(R.layout.activity_main);
return true;
}
return super.onKeyDown(keyCode, event);
}
activity_main = A layout Do I need to make Intents there? activity_main =布局是否需要在其中进行Intent设计?
You can override the onBackPressed function: 您可以覆盖onBackPressed函数:
@Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent(getApplicationContext(), ActivityA.class);
startActivity(intent);
finish();
}
When finsihing the activity is destroyed 整理活动时被销毁
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.