导航Android:如何返回上一屏幕? -- screen 领域 和 navigation 领域 和 menu 领域 android 相关 的问题

Navigating Android: How To Go Back To Previous Screen?


简体版||繁體版
3
vote

问题

中文

我想知道如何在Android上返回上一个屏幕。不只是回去。我通常在智能手机上点击"后退" 按钮,但通常存在或带我回到家时,它应该把我带到上一个屏幕。

english

I would like to know how to return to previous screen on Android. Not just go back. I usually tap "Back" button on smartphone but often it just exists or takes me back to home when it should have taken me to previous screen.

        

回答列表

5
 
vote
vote
最佳答案
 

这是一个过度简化的东西,但简单的答案是:你不能。

是什么使这一项过度简化?嗯,这是因为它取决于如何实现给定的应用程序。 Android应用程序基于活动的概念,该概念在开发文档中描述为:

一个活动是用户可以做的单一的,重点的东西。

当启动新活动时,它将其放置在堆栈顶部的系统范围内的"活动堆栈" (对于任何人不熟悉,请参阅堆栈(数据结构))。按下后按按钮,当前活动(堆栈的顶部)完成,并从堆栈中删除,导致前一个(堆叠在堆栈上)被带到前景。当您继续按下后按钮之前,此弹出/带入前景行为仍在继续,直到您在家中降落,这是堆栈的开始。从这里,你不能再去"回来" 。

现在,这是如何适用于应用的?在许多应用中,活动代表一个,单个屏幕。当您向新屏幕提升时,实际上为屏幕创建了一个新的活动,并将其推堆叠在创建它的堆栈上。在使用这种设计的应用中,击中后面的屏幕将带您到上一个屏幕。原因应该是相当不言而喻的:您当前正在查看的屏幕位于堆栈的顶部,上一个屏幕坐在下面(因为它们是每个活动本身)。因此,击中后退从堆栈中删除当前屏幕,完成它,然后加载前一个。

这不是必需的模型。您可以具有包含多个布局和屏幕的活动。我们在我的办公室里使用了它,例如,创建一个配置向导。这个想法是击中后面应该只是退出向导,并且屏幕本身上有"返回" 和"下一个" 按钮来提供导航。因此,即使您在向导的第三个屏幕上,您尚未创建任何其他活动,因此击中后按钮(硬按钮)将从"向导活动" 中带出并返回"菜单活动" 。

更进一步地,后按按钮的行为可以通过应用程序的应用来覆盖。它只需调用一个名为 onBackPressed() 的方法,该方法在活动堆栈上执行返回的默认行为。但是,如果在当前活动中存在 onBackPressed() 的覆盖实现,则将执行。

所以总结:根本不能保证背面按钮返回上一个"屏幕" 的想法。硬回合按钮处理活动,它们通常是"屏幕" 给用户,但不一定是,绝不需要。除非您使用的应用程序说,否则没有"返回一个屏幕" 的概念,但仍然没有保证由后退按钮本身提供的功能。

进一步阅读:

  • 活动和任务设计
  • 活动文档
 

This is something of an oversimplification, but the simple answer is: you can't.

What makes this an oversimplification? Well, it's because it depends on how a given app is implemented. Android applications are based around the concept of an Activity, which is described in the development documentation as:

An activity is a single, focused thing that the user can do.

When a new Activity is launched it is placed onto a system-wide "Activity stack" at the top of the stack (for anyone unfamiliar, see Stack (data structure)). When the back button is pressed, the current Activity (at the top of the stack) is finished and removed from the stack, causing the previous one (beneath it on the stack) to be brought to the foreground. This pop/bring-to-foreground behavior continues as you keep pressing the back button until you land at HOME, which is the start of the stack. From here, you cannot go "back" any further.

Now, how does this apply to apps? In many applications, an Activity represents one, individual screen. When you advance to a new screen, then, a new Activity is actually created for the screen and pushed onto the stack on top of the one that created it. In apps that use this design, hitting back will, in fact, bring you to the previous screen. The reason should be fairly self-evident: the screen you are currently viewing is on the top of the stack, the previous screen sits below it (since they are each Activities themselves). Thus, hitting back removes the current screen from the stack, finishes it, and then loads the previous one.

This is not a required model, however. You can have an Activity that contains multiple layouts and screens. We have used this in my office to, for example, create a configuration wizard of sorts. The idea is that hitting back should simply exit the wizard, and there are "Back" and "Next" buttons on the screen itself to provide navigation. Thus, even if you are on the third screen of the wizard, you have not created any additional Activities, so hitting the back button (hard button) will take you out of the "Wizard Activity" and back to the "Menu Activity".

Further, the behavior of the back button can be overridden by an application of they so choose. It simply calls a method named onBackPressed(), which performs the default behavior of going backwards on the Activity stack. However, if there is an overridden implementation of onBackPressed() in the current Activity, that will be executed instead.

So to sum up: the idea that the back button goes back to the previous "screen" is not guaranteed at all. The hard back button deals with Activities only, which are often "screens" to the user, but aren't necessarily, and are in no way required to be. There is no concept of "go back one screen" unless the app you are using says there is, but that functionality is still not guaranteed to be provided by the back button itself.

Further reading:

  • Activity and Task Design
  • Activity documentation
 
 
1
 
vote

如果一个应用程序在击中时不带您到上一个屏幕,那么你或Android就可以了解它。您可以要求应用程序的开发人员实现它,但这是关于它的。

 

If an app doesn't take you to the previous screen when you hit Back, there's nothing you or Android can do about it. You could ask the app's developer to implement it but that's about it.

 
 

相关问题

0  USB视频预览  ( Usb video preview ) 
在数字化所有家庭的旧视频镜头后,我现在正在寻找一种在家庭中分发渲染视频的方法。我将首选一个经典的DVD或Blureay与菜单,但容量是不够的。因此闪存驱动器。 Android电视似乎无法使用Flash菜单,DVD或BluRay文件夹结构或USB的磁盘图像读取HTML,以可视化菜单。现在我假设大多数设备都有一个很好的菜...

0  Hack IC浏览器恢复“菜单”按钮公开URL字段“  ( Hack ics browser to restore menu button exposes url field ) 
我刚刚收到了一个Galaxy S3,我终于被迫迫使我讨厌我Xoom上出现的那一刻的ICS的一个方面:按'MENU'按钮不再下降在URL字段中,而是迫使你一直滚动到顶部,然后将其拉下来才能获得它。 是否有任何已知的方法来重新启用原始行为(随时按MENU按钮,无论页面是否一直滚动,请参阅可编辑表单中的"URL" 字段下降...

2  使用菜单将应用程序添加到打开状态  ( Add an application to the open with menu ) 
我正在使用三星注释果冻4.1.2。 我想用列表添加一个应用程序。我下载了一张照片编辑应用程序。在画廊中,我希望能够选择一张照片并用这个应用程序打开它,但它不在列表中。 谢谢。 :) ...

2  如何在应用程序菜单中自动安排图标?  ( How do i auto arrange icons in the app menu ) 
我的设备是三星Galaxy Ace / Cooper。它在Froyo跑步。我想自动在App菜单中安排图标。有没有办法做到这一点?像Auto按字母顺序排列?是否有一个内置的功能来做这件事?或者市场上的应用程序有同样的目的? ...

12  如何在Android 6上模拟菜单按钮?  ( How do i simulate menu button on android 6 ) 
我正在使用三星Galaxy S7。长按最新按钮不会模拟菜单按钮,但激活拆分屏幕模式。长按后按钮也不适用;它只是关闭了应用程序。我正在使用需要菜单按钮的旧应用程序。任何解决方案都没有强化手机? ...

3  导航Android:如何返回上一屏幕?  ( Navigating android how to go back to previous screen ) 
我想知道如何在Android上返回上一个屏幕。不只是回去。我通常在智能手机上点击"后退" 按钮,但通常存在或带我回到家时,它应该把我带到上一个屏幕。 ...

3  如何在App菜单中手动安排图标?  ( How do i arrange the icons manually in the app menu ) 
我正在使用 micromax canvas 2 a110 android ics 4.0.4 。我安装了很少的应用程序,随机排序(或按字母顺序排序)。我想手动在App菜单上安排图标。即,在一页上设置常用应用程序,第二页上的游戏......我找不到任何选项来手动重新安排它们。 所以,如何在App菜单中手动安排图标(...

0  无法在我的Galaxy S3上访问服务菜单  ( Not able to access the service menu on my galaxy s3 ) 
我有一个来自 US Cellular 的三星Galaxy S3,我试图在不同的载体上使用它。我添加了新的SIM卡,我尝试了所有可能的选项来访问服务菜单,并且它总是说 "移动网络不可用" 。我的手机型号是SCH-R530U。谢谢。 ...

1  如何在3D中制作菜单幻灯片?  ( How to make menu slide in 3d ) 
我在这里看到它: http:/ /theunlockr.com/2011/04/12/Android-101-how-to-can-use-a-qr-code/ 观看视频,你会看到。我想知道如何在Android Gingerbread上创建这种影响。 谢谢。 ...

5  如何将应用程序组合在菜单视图中?  ( How can i group apps together in the menu view ) 
手机的菜单视图列出了我安装的所有应用程序。 所有它们。 手机已预先安装2.5页的应用程序,我最多可打电话3周... 是有没有办法将它们分组成文件夹以减少杂乱? 注(1):我正在使用Froyo 的三星Galaxy s 注意(2):我的手机的GUI在希伯来语中,所以我可能会逐步造成错误。这就是我的意思"菜单视图" :...




© 2022 it.wenda123.org All Rights Reserved. 问答之家 版权所有