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.
- 大小: 25.6 KB
- 大小: 25 KB
分享到:
相关推荐
- **Home按钮**:同样,Home按钮也需要创建一个自定义View,并在点击时启动Home Intent,以模拟原生Home键的行为。 - **Menu按钮**:在Android 2.3中,menu按钮通常是在屏幕下方,但在StatusBar中添加可能需要...
总的来说,为Android状态栏添加Menu、Back、Home按钮是一种提高用户体验的方式,但实现时需考虑系统的限制和可能存在的问题。通过处理Intent响应和使用动画效果,可以有效地解决实际使用中的问题,为用户提供更自然...
在Android开发中,监听返回按钮事件是一个常见的需求,特别是在用户交互设计中,有时需要自定义返回按钮的行为,比如弹出确认对话框防止用户误操作。本文将详细讲解如何在Android应用中实现返回按钮事件的监听。 ...
一:Android 中Home键监听和Back键监听的区别: (1).在Android中,当按下Home键的时候,默认情况下Stop前台的Activity,即Activity设置成停止状态【onStop()】,而不是销毁状态【onDestory()】。如果再次启动该...
即使那个activitie可能来自不同的应用,Android也靠着把两个activity保存在同一个任务中来实现这种无缝的用户体验. 一个任务是用户在执行某种工作时所交互的activitie的集合.activitie们放置在一个栈("后退栈")中,...
在Android开发中,有时我们需要模拟Home键的行为,使得用户点击应用内的某个按钮后,Activity不会被销毁,而是进入后台,类似于用户按下物理Home键的状态。本文将详细介绍如何在Android应用中实现这一功能。 首先,...
在Android应用开发中,有时需要模拟用户按下HOME键的效果,这通常是出于特定的用户体验考虑,例如在完成某个操作后返回主屏幕,或者在特定条件下结束当前应用而不使用物理的BACK键。以下将详细解释如何通过代码实现...
在Android4.2.2中,导航栏(也就是屏幕底部的三个按钮,home,back,recentapp)是系统应用SystemUi.apk的一部分,简言之,我们的需求就是让我们的app来控制SystemUi.apk,达到动态显示隐藏屏幕底部导航栏的效果。...
通过上述步骤,我们可以在Android状态栏中成功地添加Home、Back和Menu等快捷键。这种方法虽然较为复杂,但对于那些需要高度定制化的应用程序来说非常有用。需要注意的是,这种方法适用于具备一定开发经验和技术背景...
在Android系统中,导航栏是用户界面不可或缺的一部分,通常包含BACK、HOME和RECENT(最近应用)这三个关键按钮,为用户提供基本的操作导航。在Android 4.0(Ice Cream Sandwich)版本中,虽然这个功能是默认存在的且...
- **ActivityManagerService(AMS)**:在系统层面,AMS是处理应用切换和生命周期管理的核心服务,它会接收并处理按键事件,比如HOME键启动主屏幕,BACK键返回上一级。 3. **源码解析**: - **Android Framework...
在Xamarin.Android开发中,创建自定义标题栏是提升应用用户体验和界面个性化的重要步骤。Xamarin是一个强大的跨平台开发工具,允许开发者使用C#语言构建原生的iOS、Android和Windows应用程序。本教程将深入探讨如何...
例如,描述中的对话框可能包含"Yes"和"No"两个按钮。 2. **自定义对话框类**:创建一个继承自`AlertDialog.Builder`或`AlertDialog`的类。在这个类中,你可以设置对话框的属性,如标题、消息、按钮等,并重写其行为...
在Android开发过程中,Android模拟器扮演着至关重要的角色,它为开发者提供了一个在不依赖物理设备的情况下测试应用程序的平台。创建并配置Android模拟器是每个Android开发者必须掌握的基础技能。以下将详细介绍创建...
此外,为了使一键锁屏功能可以在任何界面下触发,通常会将其绑定到一个全局的广播接收器,监听如“HOME键”、“BACK键”等特定事件,或者自定义快捷方式、悬浮按钮等。这样,无论用户在哪个应用中,只要触发锁屏事件...
此外,`keyTest.apk`还可能提供了对特殊键值的测试,比如BACK键、HOME键、搜索键等,这些键在Android中有着特殊的含义和处理方式。通过这个工具,开发者可以确保自己的应用在处理这些系统级键值时不会出现意外的行为...
然而,对于Home键、Back键等系统键,可以通过重写Activity的onKeyDown()和onKeyUp()方法来监听。如果需要监听自定义的软键盘按键或者特定的硬件按键,可以创建一个自定义的BroadcastReceiver,然后在需要的地方发送...
然而,对于大多数标准的UI交互,Android SDK提供了丰富的控件和API,如按钮、切换开关等,这些控件会自动处理触摸事件,无需直接使用`onKeyDown`。 源码分析: 压缩包内的源码文件应该包含了具体的`onKeyDown`实现...
在Android应用开发中,有时需要实现一个功能,即在用户操作后退出所有当前栈中的Activity,但不显示任何确认对话框。这个需求通常出现在用户点击退出按钮或者进行某些特殊操作时。本文将深入探讨如何实现这个功能,...
5. **KEYCODE_BACK** (返回键):键值为4,是Android中最常用的功能键之一,用于返回上一级界面或退出当前应用。 6. **KEYCODE_SEARCH** (搜索键):键值为84,通常用于启动设备上的搜索引擎或在当前应用中执行搜索...