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

200
Visualizações
Android Studio doesn't let me use repeatOnLifecycle

I want to observe data inside my fragment from viewModel, but Android Studio keeps triggering this warning. Can someone help with this problem? Can this problem somehow be related to Android Studio Bumbleblee's update? enter image description here

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

When you write

viewLifecycleOwner.lifecycleScope.launch {
  repeatOnLifecycle(Lifecycle.State.STARTED) {
    // {code to collect from viewModel}
  }
}

The repeatOnLifecycle is an extension on a LifecycleOwner - here, you are implicitly using this - i.e., the Fragment's Lifeycle and most important not the Fragment View Lifecycle.

As seen in the documentation, you should explicitly be using viewLifecycleOwner.repeatOnLifecycle, which is exactly what the Lint check is telling you to use:

viewLifecycleOwner.lifecycleScope.launch {
  viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
    // {code to collect from viewModel}
  }
}
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