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.
J'aimerais savoir comment retourner à l'écran précédent sur Android. Pas seulement revenir en arrière. J'appuyez habituellement sur le bouton "Retour" sur le smartphone, mais cela existe souvent ou me ramène à la maison quand il aurait dû m'avoir emmené à l'écran précédent.
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.
C'est quelque chose d'une simplification excessive, mais la réponse simple est la suivante: vous ne pouvez pas.
Qu'est-ce qui en fait une simplification excessive? Eh bien, c'est parce que cela dépend de la mise en œuvre d'une application donnée. Les applications Android sont basées sur le concept d'une activité , qui est décrite dans la documentation de développement comme:
Une activité est une seule chose ciblée que l'utilisateur peut faire.
Lorsqu'une nouvelle activité est lancée, elle est placée sur une "pile d'activités" à l'échelle du système en haut de la pile (pour toute personne inconnue, voir pile (structure de données) ). Lorsque vous appuyez sur le bouton arrière, l'activité actuelle (en haut de la pile) est terminée et retiré de la pile, ce qui provoque la mise en place du précédent (sous la pile). . Ce comportement POP / ARTITRÈNE au premier plan continue lorsque vous continuez à appuyer sur le bouton arrière jusqu'à ce que vous atterrissez à la maison, ce qui est le début de la pile. D'ici, vous ne pouvez pas aller "en arrière" plus loin.
Maintenant, comment s'applique-t-elle aux applications? Dans de nombreuses applications, une activité représente un écran individuel . Lorsque vous avancez à un nouvel écran, une nouvelle activité est en fait créée pour l'écran et poussé sur la pile sur celui qui l'a créé. Dans les applications qui utilisent cette conception, frappez-vous en fait à l'écran précédent. La raison devrait être assez évidente: l'écran que vous visualisez actuellement est situé en haut de la pile, l'écran précédent est assis en dessous (puisqu'ils sont toutes les activités elles-mêmes). Ainsi, la récupération en arrière supprime l'écran actuel de la pile, la finit, puis charge la précédente.
En outre, le comportement du bouton arrière peut être ultérieurement par une application de leur choix. Il appelle simplement une méthode nommée onBackPressed()
, qui effectue le comportement par défaut d'aller en arrière sur la pile d'activités. Cependant, s'il y a une implémentation remplacée de onBackPressed()
dans l'activité actuelle, que sera exécuté à la place.
Donc de résumer: l'idée que le bouton arrière revient à l'ancien "écran" n'est pas du tout garantie. Le bouton durs du dur traite des activités
Lecture ultérieure:
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:
Si une application ne vous amène pas à l'écran précédent lorsque vous avez touché, il n'y a rien de vous ou d'Android ne peut faire à ce sujet. Vous pouvez demander au développeur de l'application de la mettre en œuvre, mais c'est à ce sujet.
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.
© 2022 www.demandez.top All Rights Reserved. Questions et réponses Accueil Tous les droits sont réservés