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.



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.

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. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Suggestion: add 'tools:replace="androi
  2. Fragment的交互及管理
  3. android 遥控器配置
  4. 《Expert Android》关键点摘录之一:Explor
  5. 【Android Training UI】创建自定义的Vie
  6. Android Media Server - MediaPlayer - s
  7. How Android Draws Views,Android如何绘制
  8. 地图引擎rmaps android 源码(rmaps sourc
  9. android学习小结4
  10. Android开发-WebSocketWssDemo