A stack of View objects
controls navigation in a mobile application. The top View object
on the stack defines the currently visible view.
The ViewNavigator container
maintains the stack. To change views, push a new View object onto
the stack, or pop the current View object off the stack. Popping the
currently visible View object off the stack destroys the View object
and returns the user to the previous view on the stack.
In an application with sections, use the tab bar to navigate
the sections. Because a different ViewNavigator defines each section,
changing sections corresponds to changing the current ViewNavigator
and stack. The View object at the top of the stack of the new ViewNavigator
becomes the current view.
To conserve memory, by default the ViewNavigator ensures that
only one view is in memory at a time. However, it maintains the
data for previous views on the stack. Therefore, when the user navigates
back to the previous view, the view can be reinstantiated with the
Note: The View container defines the destructionPolicy property.
If set to auto, the default, the ViewNavigator
destroys the view when it is not active. If set to none,
the view is cached in memory.
ViewNavigator navigation methods
Use the following methods of the ViewNavigator class to control
- Push a View object onto the stack. The View passed as an
argument to the pushView() method becomes the current
- Pop the current View object off the navigation stack and
destroy the View object. The previous View object on the stack becomes
the current view.
- Pop all View objects off the stack and destroy them, except for
the first View object on the stack. The first View object on the
stack becomes the current view.
- Empty the stack of the ViewNavigator, and destroy all View
objects. Your application displays a blank view.
following figure shows two views. To change the current view, use
the ViewNavigator.pushView() method to push a View
object that represents the new view onto the stack. The pushView() method
causes the ViewNavigator to switch the display to the new View object.
Push and pop View objects to change views.
Use the ViewNavigator.popView() method to remove
the current View object from the stack. The ViewNavigator returns
display to the previous View object on the stack.
Note: The mobile device itself controls much of the navigation in
a mobile application. For example, mobile applications built in
Flex automatically handle the back button on mobile devices. Therefore,
you do not have to add support for the back button to the application.
When the user presses the back button on the mobile device, Flex
automatically calls the popView() method to restore
the previous view.
Create navigation for an application with multiple sections
In the following figure, the Views are arranged in multiple sections.
A different ViewNavigator container defines each section. Within
each section are one or more views:
A. ActionBar B. Content area C. Tab bar
To change the view in the current section, which corresponds
to the current ViewNavigator, use the pushView() and popView() methods.
To change the current section, use the tab bar. When you switch
sections, you switch to the ViewNavigator container of the new section.
The display changes to show the View object currently at the top
of the stack for the new ViewNavigator.
You can also change sections programmatically by using the TabbedViewNavigator.selectedIndex property.
This property contains the 0-based index of the selected view navigator.