Navigating Away from an Activity with BACK and HOME keys

An activity can keep or lose its state depending on how the user leaves the activity — by the HOME or BACK key.

By default, pressing the BACK key finishes (destroys) the current activity and displays the previous activity to the user. In the following figure, the user starts email by touching the Email icon in the Home screen, which displays a list of email messages. The user scrolls down the list (changing its initial state). Pressing BACK destroys the List Messages activity and returns to the previous activity, which is Home. If the user re-launches Email, it would re-load the messages and display its initial, non-scrolled state.

Android 中的 BACK 和 HOME 按钮的区别

In the above example, pressing BACK goes to Home because it was the last activity the user was viewing. But if the user had gotten to List Message from some other activity, then pressing BACK would have returned there.

By contrast, the next figure shows the user leaving List Messages by pressing HOME instead of BACK — the List Messages activity is stopped and moved to the background rather than being destroyed. Starting Email again from its icon would simply bring the List Messages activity to the foreground (changing it from stopped to running) in the same scrolled state the user last left it.

Android 中的 BACK 和 HOME 按钮的区别

Exceptions. Some background activities return to their initial screen (they lose any state, such as scrolling) when they are brought to the foreground. This is true for Contacts and Gallery. If the user chooses Home > Contacts then chooses a contact, they are viewing the details of a contact. If they start again by choosing Home > Contacts, they are presented with the initial list of contacts rather than the contact they were last viewing. Contacts is designed this way because this initial screen is the main entry point for the application with four tabs for accessing the full range of features.

In addition, not all activities have the behavior that they are destroyed when BACK is pressed. When the user starts playing music in the Music application and then presses BACK, the application overrides the normal back behavior, preventing the player activity from being destroyed, and continues playing music, even though its activity is no longer visible — as a visual substitute, the Music application places a notification in the status bar so the user still has an easy way to get to the application to stop or control the music. Note that you can write an activity to stop when its screen is no longer visible, or to continue running in the background — the latter was chosen for the music player.

更多相关文章

  1. 毕设---android按钮事件
  2. Android Parcelable和Serializable的区别(三)
  3. android gridview按钮边框和定制点击颜色
  4. android 按钮Button单击背景切换
  5. Android 动态切换底部tab按钮
  6. Android 的 Button 按钮实现的两种方式
  7. ImageButton动态改变按钮图片
  8. android 按钮按下效果(文字颜色和按钮同时变化)
  9. EditText在输入法上显示搜索按钮

随机推荐

  1. android 自带视频播放器(MediaController)
  2. android的烧写与运行
  3. android4.2视频通讯应用源码共享
  4. 获取Android系统时间是24小时制还是12小
  5. Android 性能优化 之谈谈Java内存区域
  6. Android热修复技术原理
  7. android framework层 学习笔记(二)
  8. Android——在SurfaceView上绘图
  9. Android第二周(第二部分)-listview
  10. 【开源框架】一个基于回调机制的多线程异