- Learning Android Application Development
- Raimon Ràfols Montané Laurence Dawson
- 349字
- 2021-07-14 10:25:50
Chapter 2. Activities and Fragments - The Backbone of Your App
Activities and fragments are two of the most important concepts for an Android developer to master. In fact, in just about any Android-related programming interview, a common starting question is to ask a candidate to describe and outline activities, fragments, and their respective life cycles!
Broadly speaking, most Android apps consist of a series of connected screens that a user is able to navigate through. Obviously, more complex apps can be offered additional functionality such as background services, cloud messaging, broadcast receivers, and so on. However, the core UI will usually be centered around navigating through a series of connected activities or fragments nested within an activity.
A simple example of this basic UI in, for instance, a cooking-recipe application, would be a screen displaying a list of available recipes (Recipe List Activity) and another screen displaying details of each recipe (Recipe Detail Activity). These screens can be mapped easily to activities and managed by the system as an activity stack. In the earlier example, if a user navigates from the recipe list activity (by clicking on a recipe in the list), a new instance of the recipe detail activity is added to the stack. When a user navigates back, the current recipe detail activity is popped off the top of the stack and the user is taken back to the recipe list activity. On tablets, this pattern can be simplified by displaying both the recipe list and recipe details view within a single activity. This allows more information to be presented to users at once and to utilize the available screen space more efficiently.
In this chapter, we will introduce the following:
- Activities and fragments
- Practical examples on how activities and fragments make the backbone of any Android app
- How to create activities and fragments
- How to create custom activities and fragments
- How to allow your user to navigate through your application moving between fragments and activities
Tip
If you are more of a practical learner, I would suggest skipping straight to the Creating Activities section.
- Android Wearable Programming
- Docker技術入門與實戰(第3版)
- ASP.NET Core 2 and Vue.js
- 看透JavaScript:原理、方法與實踐
- 三維圖形化C++趣味編程
- 游戲程序設計教程
- Hands-On RESTful Web Services with Go
- SQL Server 2012數據庫管理與開發項目教程
- 零基礎學單片機C語言程序設計
- 自制編程語言
- Learning OpenStack Networking(Neutron)(Second Edition)
- Scala Reactive Programming
- 常用工具軟件立體化教程(微課版)
- Solr Cookbook(Third Edition)
- TypeScript 2.x By Example