哪些动作呢后退按钮/后退在Android上触发键? [英] Which actions does the back button/back key on Android trigger?

查看:149
本文介绍了哪些动作呢后退按钮/后退在Android上触发键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很困惑。我已阅读,后退按钮

  • <一个href="http://stackoverflow.com/questions/6848260/android-does-not-destroy-data-on-back-button/6848302#6848302">calls的onDestroy()
  • <一个href="http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon/2034238#2034238">can请大家合上当前正在运行的活动
  • 调用的onPause()

我想的onPause()应该是正确的。但是这是一个副作用,因为活动进入的背景。我什么都没有发现的文档。但也许我忽略了一些东西。

有人可以给我解释一下是应该做的后退按钮做编程?有些引用也将是不错的。 : - )

解决方案
  

我已阅读,后退按钮调用的onDestroy(),可以关闭你正在运行的活动,呼吁在onPause()

这三个是正确的。

  

我什么都没有发现在docs。

引述 Android的文档

  恢复

当用户presses BACK键,当前的活动,从堆栈顶部(活性被破坏)和previous活性弹出(其UI的previous状态是恢复)。

要详细说明,如果没有别的,这将消耗BACK按钮preSS(例如,开放式选项菜单),你的活动将被称为 onBack pressed()。此操作的默认实现调用完成()。这将需要你的活动从运行到被摧毁的状态,叫的onPause()的onStop()的onDestroy()的顺序,如在事件流程图:

I am really confused. I have read that the back button

I think onPause() should be right. But this is an side effect, because the Activity gets into the background. I found nothing in the docs. But maybe I have overlooked something.

Can someone please explain to me what the back button is supposed to do programmatically? Some references would also be nice. :-)

解决方案

I have read that the back button calls onDestroy(), can close up your currently-running activity, calls onPause()

All three are correct.

I found nothing in the docs.

Quoting the Android documentation:

When the user presses the BACK key, the current activity is popped from the top of the stack (the activity is destroyed) and the previous activity resumes (the previous state of its UI is restored).

To elaborate, if there is nothing else that will consume the BACK button press (e.g., an open options menu), your Activity will be called with onBackPressed(). The default implementation of this calls finish(). This will take your activity from the running to the destroyed states, calling onPause(), onStop(), and onDestroy() in sequence, as shown in the event flow diagram:

这篇关于哪些动作呢后退按钮/后退在Android上触发键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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