App demonstrates how to use Room to save, read, update, and delete inventory items in a SQLite database.

Related tags

App room
Overview

Inventory - Solution Code

Solution code for Android Basics in Kotlin. Codelab: Android Jetpack - Room.

Introduction

This app is an Inventory tracking app. Demos how to add, update, sell, and delete items from the local database. This app demonstrated the use of Android Jetpack component Room database.

The app also leverages ViewModel, LiveData, [Flow] (https://developer.android.com/kotlin/flow), View Binding, and Navigation with the SafeArgs plugin for parameter passing between fragments.

Pre-requisites

You need to know:

  • How to create and use fragments.
  • How to navigate between fragments, and use safeArgs to pass data between fragments.
  • How to use architecture components including ViewModel, LiveData, and LiveData transformations.
  • How to use coroutines for long-running tasks.
  • RecyclerView and adapters
  • SQLite database and the SQLite query language

Getting Started

  1. Download and run the app.
Comments
  • Android Basics: Persist data with Room

    Android Basics: Persist data with Room

    URL of codelab

    https://developer.android.com/codelabs/basic-android-kotlin-training-persisting-data-room

    In which task and step of the codelab can this issue be found?

    When trying to run the project after the "Implement Application class" step.

    Describe the problem

    The build.gradle files are not the same in the starter and main branch. The starter file is out of date and makes the whole project build crash with an error like this :

    /ItemDao.java:13: error: Type of the parameter must be a class annotated with @Entity or a collection/array of it.

    The fix was to do git checkout main -- build.gradle, it took me hours to figure out what was the problem.

    Steps to reproduce?

    1. git clone [email protected]:google-developer-training/android-basics-kotlin-inventory-app.git
    2. git checkout main
    3. open the project in android studio
    4. build the project
    5. the build works
    6. git checkout starter -- build.gradle
    7. the build crashes.

    Versions Android Studio version: 2020.3.1 API version of the emulator: N/A

    Additional information Include screenshots if they would be useful in clarifying the problem. image

    opened by renanlecaro 5
  • Android Basics: Persist data with Room - Problem with the starter code

    Android Basics: Persist data with Room - Problem with the starter code

    URL of codelab https://developer.android.com/codelabs/basic-android-kotlin-training-persisting-data-room

    In which task and step of the codelab can this issue be found? Solution code

    Describe the problem I got this error: Type of the parameter must be a class annotated with @Entity or a collection/array of it, when I finished the codelab and I fixed it by updating the room_version defined in the build.gradle. It's currently using 2.2.6, I've updated to 2.3.0.

    Steps to reproduce? Do all steps of the codelab, the run the app.

    Additional information I checked the branch room and there, this version is already updated.

    opened by brunomateus 4
  • Android Basics: Read and update data with Room

    Android Basics: Read and update data with Room

    After all code chapter 5 at the end

        private fun getUpdatedItemEntry(itemId: Int, itemName: String, itemPrice: String, itemCount: String) =
            Item(itemId, itemName, itemPrice.toDouble(), itemCount.toInt())
    

    There will be and error if you save it when in price field will be "," - it's possible because of formatter NumberFormat.getCurrencyInstance().format(itemPrice) possible fix:

        private fun getUpdatedItemEntry(itemId: Int, itemName: String, itemPrice: String, itemCount: String) =
            Item(itemId, itemName, itemPrice.replace(",", ".").toDouble(), itemCount.toInt())
    
    invalid 
    opened by pentiux 3
  • Android Basics: Persist data with Room - Build output error

    Android Basics: Persist data with Room - Build output error

    URL of codelab https://developer.android.com/codelabs/basic-android-kotlin-training-persisting-data-room

    In which task and step of the codelab can this issue be found? Probably step 6 and in step 9 when running the code

    Describe the problem Build output shows a lot of error when running such as annotation and return type of the functions in DAO, specifically:

    • error: Type of the parameter must be a class annotated with @Entity or a collection/array of it. kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);

    • error: Not sure how to handle insert method's return type. public abstract java.lang.Object insert(@org.jetbrains.annotations.NotNull()

    • error: Not sure how to handle delete method's return type. Currently the supported return types are void, int or Int. public abstract java.lang.Object delete(@org.jetbrains.annotations.NotNull()

    • error: Type of the parameter must be a class annotated with @Entity or a collection/array of it. kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);

    • error: Type of the parameter must be a class annotated with @Entity or a collection/array of it. kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);

    • error: Not sure how to handle update method's return type. Currently the supported return types are void, int or Int. public abstract java.lang.Object update(@org.jetbrains.annotations.NotNull()

    Versions Android Studio version: Chipmunk 2021.2.1 API version of the emulator: API 31

    Additional information image

    opened by Andy-Cuong 2
  • Android Basics: Persist data with Room - missing pictures

    Android Basics: Persist data with Room - missing pictures

    The 'Before you Begin' page mentions an image of how Room fits in with the overall architecture recommended in the course, however, the image seems to no longer be available.

    image

    opened by duemoselund 2
  • Android Basics: Persist data with Room

    Android Basics: Persist data with Room

    Hi, it seems that Room version '2.2.6' in the starter code's gradle is bringing error when compiling at the end of the "Persist data with Room" module. Updating it to '2.3.0' makes it work.

    opened by jblprog 2
  • Android Basics: Persist data with Room

    Android Basics: Persist data with Room

    image

    -Under 'Persist data with room', item 7 (create a database instance)

    Code at the end of the picture should 'instance' and not 'return instance'. As it is already a return statement

    opened by tobidenagan 2
  • Application Running Problem

    Application Running Problem

    URL of codelab https://developer.android.com/codelabs/basic-android-kotlin-training-persisting-data-room?authuser=1#2

    In which task and step of the codelab can this issue be found? first page of the code.

    Describe the problem

    When i am going to install the application after build, it shows only the Inventory page not and then when i am clicking add button then it is showing to add item and then item price and quantity in stock, then after if you are going to submit this by clicking save button then it shows no change on the page. Maybe it not connected to next page. Please fix this error

    Steps to reproduce?

    1. Go to...
    2. Click on...
    3. See error...

    Versions Android Studio version: Android Studio 4.2.2 API version of the emulator: Android 11 WhatsApp Image 2021-07-22 at 00 02 44

    Additional information Include screenshots if they would be useful in clarifying the problem.

    opened by MeAdarshMishra 2
  • Android Basics: Read and update data with Room

    Android Basics: Read and update data with Room

    The Room and the Main branch don't build properly for me. Working from the Starter code, it stopped working, I believe, in the 7th section of Persist Data with Room. E/LazyAlarmStore: Removed TIME_TICK alarm E/WifiDataStall: onDataConnectionStateChanged unexpected State: 3 E/MboOceController: onDataConnectionStateChanged unexpected State: 3

    opened by charleshubbert 1
  • Android Basics: Persist data with Room

    Android Basics: Persist data with Room

    Solution code couldn't build.

    Android Studio Version: BumbleBee | 2021.1.1. Patch 2 API Version of the emulator: 30

    Reproduce steps: Just using the solution code is going to reproduce the bug.

    Description of the problem: I am getting build error according to suspend function and coroutines.

    opened by Burak-Tasci 1
  • Android Basics: Persist data with Room

    Android Basics: Persist data with Room

    I've followed the examples precisely and get the following error when I create the Database class:

    Execution failed for task ':app:kaptDebugKotlin'.

    A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction java.lang.reflect.InvocationTargetException (no error message)

    • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

    Before creating the class there are no errors when I build and I'm just beginning in Android so not really sure how to resolve this.

    I'm using a macbook pro with the new M1 Max chip.

    I've tried switching from kapt "androidx.room:room-compiler:$room_version" to kapt "androidx.room:room-compiler:2.4.1" but then I get a different error:

    error: cannot find symbol import androidx.room.migration.AutoMigrationSpec; ^ symbol: class AutoMigrationSpec location: package androidx.room.migration

    opened by alionthego 1
  • Android Basics: Persist data with Room

    Android Basics: Persist data with Room

    companion object { @Volatile private var INSTANCE: ItemRoomDatabase? = null fun getDatabase(context: Context): ItemRoomDatabase { return INSTANCE ?: synchronized(this) { val instance = Room.databaseBuilder( context.applicationContext, ItemRoomDatabase::class.java, "item_database" ) .fallbackToDestructiveMigration() .build() INSTANCE = instance return instance -----------------------> this need delete "return" } } }

    opened by vladkozhukh 0
  • Android Basics: Read and update data with Room

    Android Basics: Read and update data with Room

    companion object {
           private val DiffCallback = object : DiffUtil.ItemCallback<Item>() {
               override fun areItemsTheSame(oldItem: Item, newItem: Item): Boolean {
                   return oldItem === newItem
               }
    
               override fun areContentsTheSame(oldItem: Item, newItem: Item): Boolean {
                   return oldItem.itemName == newItem.itemName
               }
           }
       }
    

    In this companion object, the function areItemsTheSame has the ===. I think it's an typo mistake.

    opened by dmdbilal 0
  • Android Basics: Read and update data with Room

    Android Basics: Read and update data with Room

    InventoryViewModel.kt,

    In "Step 5, Implement sell item", sub-step 'Update the entity using Room' sub-sub-step 4. states that inside the 'updateItem()' function, we are to make a call to the 'getUpdatedItemEntry()' function and assign the returned value to an immutable variable called 'updatedItem'.

    "val updatedItem" is not used?

    In Android Studio, this value is grey, indicating it isn't used in the app. I've checked the solution code, and I can't find the error.

    opened by nicguy59 1
  • Android Basics: Persist data with Room

    Android Basics: Persist data with Room

    Hi, I have errors happening both when I have followed step by step the tutorial using the starter code and also when I use the solution code.

    Starter code branch name: starter Solution code branch name: room

    The errors that happens, do happen in different scenario depending which code is used.

    Error 1: When running starter code after all steps in the tutorial have been completed and the below scenario happens. Scenario:

    • I have multiple inventory items, and I therefore they show up in the list view.
    • I click on the item at the top of the list view which directs me to the detail page for that item.
    • I then click 'Delete' button and click 'Yes' in the pop up confirmation dialogue and I am directed back to the list view.
    • When back to the list view there is a split-second, where the deleted item, from previous step, is still visible in the list view until the list view updates to reflect that the item is deleted and hence not showing. If I am really fast and manage to click the item during that split-second, then the app crashes [Inventory has stopped].

    Error 2: When running solution code and the below scenario happens. Scenario:

    • I open/start the app for the very first time.
    • I click the floating action button (+) to add a new item to my inventory, and I am directed to the Add Item page.
    • I enter values for the required input fields (Item Name, Item Price, and Quantity in Stock) and press [Save] button which leads to the app crashes [Inventory has stopped].

    Does anyone else experience that the app crashes in the above to scenarios? Either error (1) using the starter code after completing the tutorial. Or error (2) using the solution code.

    I would appreciate if anyone would have time to help.

    Kind regards Kirstine

    opened by kirstine78 0
  • Android Basics: Persist data with Room

    Android Basics: Persist data with Room

    error: Type of the parameter must be a class annotated with @Entity or a collection/array of it. kotlin.coroutines.Continuation<? super kotlin.Unit> continuation);

    opened by N-o-M-o-r-e 0
Owner
Google Developer Training
Google Developer Training
It is an Android app that uses an SQLite database to store an inventory of products

A project completed for a Udacity course. It is an Android app that uses an SQLite database to store an inventory of products. Each product’s name, price, quantity available, supplier, and picture are tracked. The main screen lists all products in a list and provides a button to add a new product. Clicking on a product shows a detailed view for that product. Options to modify or delete the product are available in this detailed view.

David Read 1 Jan 10, 2022
The app helps add , update, delete task

Task-Keeper The app helps add , update, delete task laguage used Kotlin The next Update jetpack-compose to showcase the use of all this features for n

Mohamed Dekow 5 Jun 25, 2022
A beautiful android Quotes App where you can read and save quotes.

This repository contains source code of a Quotes app, which helps you stay motivated by providing best picked quotes stated by famous personalities. This app uses zen quotes api, for retrieving quotes.

Gourav Khunger 34 Nov 14, 2022
A manga reader app that can be used save / search / find and read latest manga / manhwa

A manga reader app that can be used save / search / find and read latest manga / manhwa

Sebin P Johnson 3 Nov 20, 2021
A beautiful android Quotes App where you can read and save quotes.

QuotesApp A beautiful Quotes App where you can read and save quotes. This repository contains source code of a Quotes app, which helps you stay motiva

Gourav Khunger 24 Nov 12, 2021
Self hosted read and to-read list book tracker

JELU Official documentation Like Jelu or find it useful ? Offer me a coffee ☕ Purpose This app main purpose is to track what you have read, what you a

null 181 Dec 28, 2022
SimpleToDo is an android app that allows building a todo list and basic todo items management functionality including adding new items, editing and deleting an existing item.

SimpleToDo is an android app that allows building a todo list and basic todo items management functionality including adding new items, editing and deleting an existing item.

null 0 Jan 3, 2022
Todo List Application is an android app that allows building a todo list and basic todo items management functionality including adding new items, editing and deleting an existing item

Todo List Application is an android app that allows building a todo list and basic todo items management functionality including adding new items, editing and deleting an existing item

null 0 Jan 22, 2022
Register-Yourself - This app uses SQLite database to sign-up and register a user

Register-Yourself This Android app uses SQLite database to sign-up and register a user. Short description This is a basic application where a user sig

Vaibhav Khulbe 2 Jul 16, 2021
Simple Notes app demonstrates modern Android development with Hilt, Material Motion, Coroutines, Flow, Jetpack (Room, ViewModel) based on MVVM architecture.

Simple Notes app demonstrates modern Android development with Hilt, Material Motion, Coroutines, Flow, Jetpack (Room, ViewModel) based on MVVM architecture.

Aravind Chowdary 2 Sep 3, 2022
RedditNews - A simple application to display the top news from the Reddit API site and save your favorites to a local database.

RedditNews - A simple application to display the top news from the Reddit API site and save your favorites to a local database. Arch

null 1 Aug 28, 2022
An small android app based on banking logic, usilng SQLITE as database, material design, navigation drawer implemented

Android Banking App Project - Using Sqlite The Banking app using java in android studio and sqlite for crud. Packages Used Material Design Contributin

Md-Mahin-Rahman 4 Dec 6, 2022
Application that shows a store's phone inventory

PhoneInventory Application that shows a store's phone inventory The Basics A basic inventory application that shows a store's inventory. Tech Kotlin 1

Ayana Bando 0 Nov 3, 2021
A quiz app built with trivia api. This app was built with mvvm architecture, dagger-hilt, retrofit, room database, and navigation components.

A quiz app built with trivia api. This app was built with mvvm architecture, dagger-hilt, retrofit, room database, and navigation components.

Stephen Odumirin 3 Dec 19, 2022
ShopKeeper - A simple android app for sellers. The seller can add, edit and delete products that are bought by customers

ShopKeeper - A simple android app for sellers. The seller can add, edit and delete products that are bought by customers

Amit Kumar guha 1 Feb 23, 2022
A sample app that shows how to easily encrypt the room database in an Android app

A sample app that shows how to easily encrypt the room database in an Android app. The password used for encryption is generated on the first use and saved in the Android EncryptedSharedPreferences.

Lenz Karbaumer 3 Oct 26, 2022
Wiped is a wiping app that helps you to delete a file permanently from your device

Wiped Wiped is a wiping app that helps you to delete a file permanently from your device. How Is It Done? Did you know that when you delete a file in

null 1 May 16, 2022