Project: Water Me! app

1. Before you begin

This codelab introduces a new app called Water Me that you'll build on your own. This codelab walks you through the steps to complete the Water Me app project, including project setup and testing within Android Studio.


  • This project is for students who have completed Unit 6 of the Android Basics in Kotlin course.

What you'll build

  • Schedule a notification using a custom Worker in an existing app.

What you'll need

  • A computer with Android Studio installed.

2. Finished app overview

The Water Me! app consists of a list of plants, some information about them, and a description for how often each one should be watered. For each of these plants, the completed app will schedule a reminder for when they should be watered.


Reminders will be displayed as notifications on the device, even if the Water Me! app is not running. Tapping a notification launches the Water Me! app.


For this functionality to work, your task is to schedule a background task using a custom Worker that displays the notification.

3. Get started

Download the project code

Note that the folder name is android-basics-kotlin-water-me-app. Select this folder when you open the project in Android Studio.

To get the code for this codelab and open it in Android Studio, do the following.

Get the code

  1. Click on the provided URL. This opens the GitHub page for the project in a browser.
  2. On the GitHub page for the project, click the Code button, which brings up a dialog.


  1. In the dialog, click the Download ZIP button to save the project to your computer. Wait for the download to complete.
  2. Locate the file on your computer (likely in the Downloads folder).
  3. Double-click the ZIP file to unpack it. This creates a new folder that contains the project files.

Open the project in Android Studio

  1. Start Android Studio.
  2. In the Welcome to Android Studio window, click Open an existing Android Studio project.


Note: If Android Studio is already open, instead, select the File > New > Import Project menu option.


  1. In the Import Project dialog, navigate to where the unzipped project folder is located (likely in your Downloads folder).
  2. Double-click on that project folder.
  3. Wait for Android Studio to open the project.
  4. Click the Run button 11c34fc5e516fb1c.png to build and run the app. Make sure it builds as expected.
  5. Browse the project files in the Project tool window to see how the app is set-up.

4. Schedule notification using WorkManager

All the functionality for the Water Me! app is already implemented, except for the part to schedule and a notification. The code for displaying a notification is in WaterReminderWorker.kt (in the worker package). This happens in the doWork() method of a custom Worker class. Because notifications may be a new topic, this code is already implemented.

override fun doWork(): Result {
    val intent = Intent(applicationContext, {

    val pendingIntent: PendingIntent = PendingIntent
        .getActivity(applicationContext, 0, intent, 0)

    val plantName = inputData.getString(nameKey)

    val builder = NotificationCompat.Builder(applicationContext, BaseApplication.CHANNEL_ID)
        .setContentTitle("Water me!")
        .setContentText("It's time to water your $plantName")

    with(NotificationManagerCompat.from(applicationContext)) {

    return Result.success()

Your task is to create a OneTimeWorkRequest that will call this method with the correct parameters from PlantViewModel.

Create work requests.

To schedule the notification, you'll need to implement the scheduleReminder() method in PlantViewModel.kt.

  1. Create a variable called data using Data.Builder. The data should consist of a single string value where WaterReminder.Worker.nameKey is the key and the plantName that was passed into scheduleReminder() is the value.
  2. Create a one-time work request using WaterReminderWorker, using the delay and unit passed into the scheduleReminder() function, and setting the input data to the data variable you created.
  3. Call the workManager's enqueueUniqueWork() method, passing in the plant name, using REPLACE as the ExistingWorkPolicy, and the work request.

Your app should now be working as expected. Since each reminder will take a long time to appear, we recommend running the included tests to verify that the notification works as expected.

5. Testing instructions

Running your tests

To run your tests, you can do one of the following.

For a single test case, open up a test case class and click the green arrow to the left of the class declaration. You can then select the Run option from the menu. This will run all of the tests in the test case.


Often you'll only want to run a single test, for example, if there's only one failing test and the other tests pass. You can run a single test just as you would the entire test case. Use the green arrow and select the Run option.