Android工具栏:如果按下向后箭头,如何返回上一个活动 [英] android toolbar: how to go back to previous activity if back arrow is pressed
本文介绍了Android工具栏:如果按下向后箭头,如何返回上一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为Place
我从以前的活动City
进入Place
活动.
I come to Place
activity from its previous activity called City
.
我使用以下代码在Place
活动的工具栏中添加了后退按钮:
I have added back button to the toolbar in Place
activity using the following code:
Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true)
我想设置返回按钮以返回City
活动
I want to set the back button to go back to City
activity
但是City
活动需要一些参数传递给它.
But City
activity needs some parameters to be passed to it.
因此,如何告诉后退按钮转到城市活动,而无需将参数传递给它.
So how to tell the back button to go to City activity, without need to pass the parameters to it.
推荐答案
在您的backButton
中,您只需调用finish();
,然后关闭Activity,而无需将参数传递给其他Activity.
In your backButton
you just call finish();
and you close Activity without need to pass parameter to other Activity.
这篇关于Android工具栏:如果按下向后箭头,如何返回上一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文