scottnj avatar image
scottnj asked Jacob Abrams edited

List of items belonging to a category using InventoryContract

What is the best option to query a list if items, including the item name and id, using the InventoryContract?

Some merchants can have a very large catalog of categories and inventory items so performance may be an issue in those situations. What would give the best user experience on Clover hardware for merchants with large inventory catalogs? How does the Clover team do it for the Register App?

Using the InventoryContract.Category.contentUriWithAccount(cloverAccount) Uri we can get the categories which include a list of item id's belonging to each category.

Now to get the Items using the InventoryContract.Item.contentUriWithAccount(cloverAccount) Uri. I can see 3 ways to do this.

Option 1

Do a single query and retrieve ALL the items and store them in memory. When a category is selected, filter that list to using the IDs from the category

Advantage: only a single query

Disadvantage: Storing a what can be a really large list of ALL the item ids and names in memory.

Disadvantage: Need to filter the long list.

Option 2

When a category is selected, do a query to the items Uri passing in the item IDs as selection args.

Advantage: Storing less data in memory.

Disadvantage: The list of IDs belonging to a category may be large. Is there a limit to the number of selection args that can be passed into a content resolver query?

Disadvantage: Need to do a query for every category that is selected

Option 3

Have the recycler view query the items Uri, or even use the InventoryConnector, for each item it is displaying on screen.

Advantage: Only using the memory for what the recycler view need to display on screen

Disadvantage: A query for every inventory item

Disadvantage: Complicates the view code

Clover Android SDKInventory
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

Jacob Abrams avatar image
Jacob Abrams answered Jacob Abrams edited

Your question isn't specific to developing for Clover, it's a general android development question: How to access and display large datasets via content provider in android?

Google tends to re-vamp its suggested ways of doing android development every 4 or so years so note that you are going to find a variety of answers out there on the web depending on the year it was written.

You must use ContentResolver query to access the data since that is how Clover provides inventory data. Next question how to query and what to do with the Cursor that is returned? If you try to query everything and then load every single row out of the returned Cursor into objects you will run out of memory and/or performance will be poor. Even if you limit the query to a single category you may still have the same problem.

This is why Google invented things like Adapters and RecyclerView and Paging. These tools allow you to read chunks of data from a large dataset without needing to load all the data at once.

You should not be doing a query for each item, nor should you be loading a potentially large number of items into memory at the same time.

There are basically two solutions:

  • Do a single query for all items and iterate over the returned Cursor loading only rows needed as the user navigates your app (Google's originally recommended system up to 2017). This solution generally involved using CursorLoader and CursorAdapter.

  • Do one query at a time that returns the data in fixed size chunks, querying different chunks as the user navigates your app (Google recommendation post-2017). This solution generally involves using the Paging library and LiveData.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Thanks for pointing me in the right direction. It looks like I will try implementing the paging strategy.

Does Clover have limits on the

  • Max number of inventory items
  • Max number of categories
  • Max number of items per category

that a merchant can have?

0 Likes 0 ·

Limit was on items a limit of 15000, maybe higher now but prepare for 20000 items or more

Last I checked there was a limit of 100 categories

Limit 1000 items per category

These limits may be increased in the not too distant future though so be prepared.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community