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

258
Visualizações
Live Data: Candidate resolution will be changed soon

In same cases Android studio displays warning message when I call observe method of LiveData object

viewModel.emailValidationResult.observe(viewLifecycleOwner, {onEmailChanged(it)})

Candidate resolution will be changed soon, please use fully qualified name to invoke the following closer candidate explicitly:

public open fun observe(owner: LifecycleOwner, observer: Observer<in Int?>): Unit defined in androidx.lifecycle.LiveData

As I understand it's happened after updating kotlin 1.4 What does it actually mean ?

over 4 years ago · Hanz Gallego
5 Respostas
Responde à pergunta

0

It means that the extension in androidx is not needed anymore.

Simply remove its import import androidx.lifecycle.observe.

It will be actually deprecated in androidx. Read more reasoning there.

EDIT:

Please note the "issue" from Erik Hoogendoorn

This change causes values from the observed LiveData object to be interpreted as nullable(since the converted lambda syntax is based on nullable Java code). This was not the case for the Kotlin extension and causes a loss in functionality for the user. In my opinion this change should be reverted and a different solution found.

I'm curious if they will rename & retain the helper or come up with another solution.

over 4 years ago · Hanz Gallego Relatório

0

AndroidX extension is deprecated, so we have to use the original one.

Remove import androidx.lifecycle.observe

then

viewModel.liveData.observe(viewLifecycleOwner, Observer { result ->
    
})

or

viewModel.liveData.observe(viewLifecycleOwner) { result ->
                
}
over 4 years ago · Hanz Gallego Relatório

0

In my case I used Kotlin 1.4.31 in buildgradle(project level) file.

 ext {
    kotlin_version = '1.4.31'
}

 dependencies {
 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}

The warning/deprecation error was gone.

over 4 years ago · Hanz Gallego Relatório

0

I tried remove the "import androidx.lifecycle.observe" and converted our observers like the following:

// From this
livedata.observe(viewLifecycleOwner, Observer<MyClass?> {
    // do stuff with it
})

// To this
livedata.observe(viewLifecycleOwner) {
    // do stuff with it
}

The issue occured when we need to remove the observer inside the onChange call, e.g.

    // From this
    livedata.observe(viewLifecycleOwner, object : Observer<MyClass?> {
        override fun onChanged(t: MyClass?) {
            // Do stuff with it t
            livedata.removeObserver(this)
        }
    })
    
    // To this
    livedata.observe(viewLifecycleOwner) {
        // do stuff with it
        livedata.removeObserver(this) <--- not working ofc
    }

I've heard rumors that folks have broken out the observer as a variable and thus been able to add/remove it by referencing the variable. However I'm unable to figure out how to instantiate a local observer without using the "Observer<MyClass?> syntax.

over 4 years ago · Hanz Gallego Relatório

0

The same issue occurred my code base too. The kotlin version is '1.4.32'

After removing below import sentiment, the warning disappeared.

import androidx.lifecycle.observe
over 4 years ago · Hanz Gallego 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