Introducing Android Sunflower
A gardening app illustrating Android Jetpack development best practices
Google announced Android Jetpack at Google I/O 2018. Jetpack is a collection of Android software components to make it easier for you to develop great Android apps. These components help you follow best practices, free you from writing boilerplate code, and simplify complex tasks, so you can focus on the code you care about.
To help developers learn how to integrate Jetpack components into their own apps, we created Sunflower, a gardening app illustrating Android development best practices with Android Jetpack. If you’re new to Jetpack, it’s a good idea to check out the Jetpack content on developer.android.com and build your first simple, Jetpack-based app before continuing.
This article about Sunflower is the first in a series. It takes you on a tour of Sunflower and briefly explains which Jetpack components are included in the app. Future articles will discuss Jetpack and Android development and dive deeper into specific topics like Navigation and scheduling recurring tasks with WorkManager.
A quick garden tour
When the app is first launched, the user sees the “My Garden” screen, which is initially empty.
Let’s add a plant! Navigate to a list of plants by tapping on the hamburger menu and opening the navigation drawer.
Each plant is associated with a Grow Zone, which is determined by latitude and indicates the region best suited for the plant to thrive. You can filter the list of plants by tapping the filter menu item which selects a Grow Zone.
Tapping on a specific plant will navigate to the Plant Detail screen.
The plant detail screen shows the plant’s name, description, watering needs, and a picture of the plant. The user can add the plant to their garden from this screen by tapping on the Floating Action Button. They can also Share the plant via the menu option.
After one or more plants are added, each new plant appears in the “My Garden” screen, along with the date it was planted and when it next needs to be watered. Let’s navigate back to “My Garden” to see the screen now that we’ve added a plant or two.
The “My Garden” screen now shows the added plants, along with the date they were planted and last watered.
Using Jetpack components
Sunflower uses many Jetpack components. Here’s a brief look at how each component plays its part:
- Sunflower is written entirely in Kotlin, using Android KTX. Android KTX is a set of Kotlin extensions that optimizes Jetpack and Android platform APIs for more concise and idiomatic Kotlin code.
- The app uses a single Activity with multiple Fragments. Transitions between fragments use the Navigation component and transition animation actions.
- The screens use fragment layouts, created using ConstraintLayout and Data Binding
- On-device data storage of the plant list and my garden entries are managed with Room at the database level, and surfaced to the UI through ViewModels via LiveData
- AppCompat is used to preserve key app functionality on older versions of Android
- Background tasks are handled by WorkManager
- Plant details can be shared with other applications on the device, or simply copied to the clipboard
- Testing is performed by both local JUnit tests and Espresso Android UI tests
Sunflower is currently released as an alpha and is undergoing heavy development, with new features and deeper component integrations landing regularly. Some of these upcoming improvements include filtering the plant list based on the user’s location, migrating to AndroidX, and notifying when a plant needs watering.
Create and vote for issues on GitHub that you’d like to see implemented or explored.
In future articles we’ll explore using other Jetpack components in Sunflower such as navigation and recurring tasks, so stay tuned. Thanks for reading!
- Check out the code for Sunflower at https://github.com/googlesamples/android-sunflower.
- Learn about Jetpack and build your first Jetpack app.
Thanks to the wonderful individuals on the Android Developer Relations and Jetpack teams for their contributions to Sunflower and this article.