Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
In diesem Dokument wird beschrieben, wie die Verwendung von Dialogzielen spezielle Überlegungen zur Verwaltung des Back-Stacks enthalten kann.
Übersicht
Mindestens ein Dialogfeldziel darf nur oben auf dem Back-Stack vorhanden sein.
Das liegt daran, dass NavController automatisch alle Dialogfeldziele aus dem Stack entfernt, wenn der Nutzer ein Ziel aufruft, das kein Dialogziel ist. Dadurch wird sichergestellt, dass das aktuelle Ziel immer vollständig vor anderen Zielen auf dem Back Stack sichtbar ist.
Wenn der Back-Stack ausschließlich aus gehosteten Zielen besteht, die den Navigationshost ausfüllen, und der Nutzer zu einem Dialogziel navigiert, könnte der Back-Stack in Abbildung 2 aussehen:
Abbildung 2: Ein Back-Stack mit einem Dialogfeldziel im oberen Bereich.
Wenn der Nutzer dann zu einem anderen Dialogziel navigiert, wird es oben im Back-Stack platziert, wie in Abbildung 3 dargestellt:
Abbildung 3: Ein Back-Stack mit zwei Dialog-Zielen im oberen Bereich
Wenn der Nutzer dann zu einem nicht schwebenden Ziel navigiert, werden zuerst alle Dialogziele vom oberen Rand des Back Stacks entfernt, bevor das neue Ziel aufgerufen wird (siehe Abbildung 4):
Abbildung 4: Die Dialog-Ziele werden per Pop-up abgerufen und das neue Ziel wird hinzugefügt.
Alle Inhalte und Codebeispiele auf dieser Seite unterliegen den Lizenzen wie im Abschnitt Inhaltslizenz beschrieben. Java und OpenJDK sind Marken oder eingetragene Marken von Oracle und/oder seinen Tochtergesellschaften.
Zuletzt aktualisiert: 2025-07-27 (UTC).
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Benötigte Informationen nicht gefunden","missingTheInformationINeed","thumb-down"],["Zu umständlich/zu viele Schritte","tooComplicatedTooManySteps","thumb-down"],["Nicht mehr aktuell","outOfDate","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Problem mit Beispielen/Code","samplesCodeIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-07-27 (UTC)."],[],[],null,["# Dialog destinations\n\nThis document outlines how the use of [dialog destinations](/guide/navigation/design) can introduce\nunique considerations for how you need to manage your back stack.\n\nOverview\n--------\n\nOne or more dialog destinations can only exist on the top of the back stack.\nThis is because when the user navigates to a destination that is not a dialog\ndestination, the `NavController` automatically pops all dialog destinations off\nthe top of the stack. This ensures that the current destination is always fully\nvisible over other destinations on the back stack.\n\nDestinations can be either [hosted destinations](/guide/navigation/design), [activity\ndestinations](/guide/navigation/design/activity-destinations), or [dialog destination](/guide/navigation/design/dialog-destinations).\n| **Note:** Dialog destinations implement the [`FloatingWindow`](/reference/androidx/navigation/FloatingWindow) interface. As such, they overlay other destinations on the back stack.\n\nExample\n-------\n\nIf the back stack consists solely of [hosted destinations](/guide/navigation/design)\nthat fill the navigation host, and the user navigates to a dialog destination,\nthen the back stack might look similar to figure 2:\n**Figure 2.** A back stack with a dialog destination on top.\n\nIf the user then navigates to another dialog destination, it is then added to\nthe top of the back stack, as shown in figure 3:\n**Figure 3.** A back stack with two `Dialog` destinations on top.\n\nIf the user then navigates to a non-floating destination, any dialog\ndestinations are first popped from the top of the back stack before navigating\nto the new destination, as shown in figure 4:\n**Figure 4.** The `Dialog` destinations are popped, and the new destination is added."]]