Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

408
Vistas
How can I know @Insert of Room is completed?

My scenario

I use Coroutines and Room to save my app's user profile data. I have CompleteProfileActivity :in that User fill their information and confirm it( Confirm button ). I send them to server and observe response. If response is success. I save them to my ProfileDatabase.

My question How can I know my database is updated or my insertion is complete, my deletion is completed not by getting the size? @Insert @Delete is void return methods. So how can I know except the database size?

@Dao
interface ProfileDao {
@Insert(onConflict = OnConflictStrategy.IGNORE)
fun saveProfile(model:Profile)

@Query("SELECT * FROM profile_table")
fun getProfile():Deferred<Profile>
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

If the method call succeeded for insert, then it was succesful, otherwise you'd get an exception.

Also, these don't have to be void-returning methods.

You can have @Insert return the type of the primary key in the table, which will be the key of the newly inserted record.

@Insert(onConflict = OnConflictStrategy.IGNORE)
fun saveProfile(model: Profile): Int

In case of @Delete, it will return the number of rows deleted if you return an Int:

@Delete
fun deleteProfiles(profiles: List<Profile>): Int

Same goes for a more manual implementation using @Query, returns the number of rows affected if you return an Int:

@Query("DELETE FROM profiles")
fun deleteAllProfiles(): Int
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda