通过自定义后退按钮返回到上一个活动的问题
我有一个自定义后退按钮,目前除了转到后退堆栈上的上一个活动之外什么也不做。这是按钮的代码:
backButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
System.out.println("!!! BACK !!!");
finishActivity(0);
}
});
问题是,它不起作用。根本没有任何变化。
谁能告诉我我在这里做错了什么?谢谢。
I have a custom back button that for the time being does nothing other than going to the previous activity on the back stack. Heres the code for the button :
backButton.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
System.out.println("!!! BACK !!!");
finishActivity(0);
}
});
The problem is, its not working. There is simply no change.
Can anyone kindly tell me what I have done wrong here ? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
finishActivity 完成您之前使用 startActivityForResult() 启动的活动,但它不会完成您当前所在的活动 - finish()这样做。
finishActivity finishes an activity that you had previously started with startActivityForResult(), it doesn't finish the activity you are currently in - finish() does that.
使用
finish()
而不是finishActivity()
。finishActivity()
强制退出通过startActivityForResult()
启动的活动,但它不会完成当前活动。您还可以使用onBackPressed()
,它仅在内部调用finish()
(请参阅 默认实现),所以它具有相同的效果。如果您覆盖后退按钮行为,则很有用。Use
finish()
instead offinishActivity()
.finishActivity()
forces an activity that you started viastartActivityForResult()
to quit, it doesn't finish the current activity. You can also useonBackPressed()
, that just callsfinish()
internally (see the default implementation), so it has the same effect. Useful if you override the back button behaviour though.