Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] Android Paging library sqlite data storage concern

Posted on November 14, 2022

Solution 1 :

RemoteMediator has an initialize API which is guaranteed to complete before loading starts. You can override initialize to check for data staleness to do any setup you need (such as pruning old entries), though I’d personally be a bit surprised if only 1000 rows was causing significant performance issues.

For hot code paths such as these PagingSource queries, you can look to androidx.benchmark to figure out if it’s worth optimizing for.

Edit: You may want to consider simply clearing the table on a successful remote refresh if you don’t want to keep any of the old tweets on refresh as that’s the simplest approach. initialize is meant for the case where you need to do manual pruning / setup / staleness checks (e.g., you can check how old your data is and decide if you want to refresh or not), but simply clearing in remote refresh before inserting the new page works well because you’d expect to have to restart pagination anyway. Make sure to do the clear + insert in the same transaction so you don’t end up with two invalidates due to db updates!

Problem :

Over the past days I have been getting comfortable with Android Architecture Components and I’ve been mostly interested in the Paging Library for handling and displaying lists of data from a remote source.
For the best UX it is better to load data first into the database, in this case Room then display it in a recyclerview using the pagingLibrary and adapters. My concern is this, lets say an api has 1000s of records or a twitter feed even and all this data has to pass through the db then to the UI, how to handle this storage on the device? Seeing as storing all the data on the device is a bad idea. Is there a way to remove ‘stale’ data or what is the recommended way of doing this?

READ  [ANSWERED] python - Kivy app can't find/read my txt file in root directory Android
Powered by Inline Related Posts

Edit:
The android team has been working on V3 for the paging library here is a link to an article that might shed more light article here

Comments

Comment posted by Ikiugu

Thanks diam for this, I will look at the RemoteMediator. The 1000 was just hypothetical, I was actually thinking in the context of Twitter and feeds, in my mind I was wondering if ultimately all the tweets you go through would, in this context, be saved on the device db

Comment posted by dlam

Yes, but you can remove old tweets in db on a successful remote refresh, since you’ll be retrieving a fresh copy of that feed and paginating off of that. If for some reason you need to keep the tweets in db longer you can use the initialize method to prune or do any initial setup, but i suspect simply clearing the table on remote refresh would work for you. I’ll edit my answer since its a bit clearer to me what you’re trying to achieve now 🙂

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress