Android的后退按钮问题 [英] Android back button problem

查看:125
本文介绍了Android的后退按钮问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有3个活动在我的应用程序:A,B和C的流量虽然应用程序是:A - > B - > C

Say I have 3 Activities in my application: A, B and C. The flow though the application is: A -> B -> C.

一旦在C,pressing后退按钮如果用户presses后退按钮另一次,他们到了一个,最后他们是否preSS这一次将采取用户B.他们退出应用程序。

Once at C, pressing the back button will take the user to B. If the user presses the back button another time they got to A, and finally if they press it one more time, they exit the application.

目标:当用户presses C上的后退按钮,就应该去和不可以 B,如果他们preSS个时间,他们退出应用程序。

Objective: When the user presses the back button on C, they should go to A and not B, and if they press it another time, they exit the app.

问题:当覆盖在活动C中的后退按钮来启动活动A一切似乎都OK。但是,如果用户$ P $再次psses返回按钮,他们返回到活动C.所以pressing后退按钮只是活动A和活动℃之间切换。

Problem: When overriding the back button on Activity C to launch Activity A everything appears to be ok. However if the user presses the back button again, they return to Activity C. And so pressing the back button just switches between Activity A and Activity C.

我猜活动堆栈的样子:


  • 开启的应用程序: A

  • 转到乙: A,B

  • 转到C: A,B,C

  • preSS回: A,B,C,A

  • preSS回: A,B,C

  • preSS回: A,B,C,A

  • preSS回: A,B,C

  • preSS回: A,B,C,A

  • preSS回: A,B,C

  • preSS回: A,B,C,A

  • ...等

  • Open app: A
  • Go to B: A, B
  • Go to C: A, B, C
  • Press back: A, B, C, A
  • Press back: A, B, C
  • Press back: A, B, C, A
  • Press back: A, B, C
  • Press back: A, B, C, A
  • Press back: A, B, C
  • Press back: A, B, C, A
  • ...etc

如此看来错误是当C上的后退按钮pressed推出一项新的活动?无论如何,我可以做就如何实施这一行为的建议。

So it seems the mistake is to launch a new Activity when the back button on C is pressed? Anyway, I could do with advice on how to implement this behaviour.

谢谢,
杰克

推荐答案

您可以添加完成()的onStop() b活动的方法。

You can add finish() in the onStop() method of activity B.

此方式,当活动B就不再是可见的,它会被从栈破坏并除去。

This way, when the activity B will no longer be visible, it will be destroyed and removed from the stack.


  • 开启的应用程序: A

  • 转到乙: A,B

  • 转到C: A,C

  • preSS回为 A

  • preSS回:退出

这篇关于Android的后退按钮问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆