Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

411
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda