

– cited from the Google’s API guide for Fragments. By dividing the layout of an activity into fragments, you become able to modify the activity’s appearance at runtime and preserve those changes in a back stack that’s managed by the activity. Fragments allow such designs without the need for you to manage complex changes to the view hierarchy. Because a tablet’s screen is much larger than that of a handset, there’s more room to combine and interchange UI components. Then, with API level 11 came fragments… World of FragmentsĪndroid introduced fragments in Android 3.0 (API level 11), primarily to support more dynamic and flexible UI designs on large screens, such as tablets. It can become very complex when you need to manipulate the back stack or when you have to reuse the same activity multiple times, for example when you would like to navigate the user through some tutorial screens but each screen in fact uses the same activity as a base.įortunately we have tools for it called tasks and some guidelines for proper back stack navigation. Of course this navigation diagram is a fairly a simplistic approach. Open it with a startActivity() from another activity.When you need to add a new Activity you need to perform the following steps: When you need to communicate between activities you can use the startActivityForResult() or maybe you share a globally accessible business logic object between them. As you navigate in the application there is an activity back stack maintained by the OS.Ī simple example is shown in the diagram below:Īctivity A1 is the entry point in our application (for example, it represents a splash screen or a main menu) and from it the user can navigate to A2 or A3. World of ActivitiesĪ typical Android application which uses only activities is organized into a tree-like structure (more precisely into a directed graph) where the root activity is started by the launcher.

A demo application implementing this pattern has been uploaded to GitHub. In this article we will look at some common navigation pattern implementations in Android, and then introduce the Fragment based navigation pattern, comparing and contrasting with the others. This approach not only simplifies how the navigation is implemented, but it has much better performance and consequently offers a better user experience. One of my favorite navigation pattern implementations is based on the “One-Activity-Multiple-Fragments” philosophy, or simply the Fragment Navigation Pattern, where every screen in the application is a full screen Fragment and all or most of these fragments are contained in one Activity. Some of the apps were using only Activities, while others Activities mixed with Fragments and/or with Custom Views. Over the years, I’ve seen many different navigation pattern implementations in Android.
