I am trying to register the application to the observer but I get this message:
requires: 'android.arch.lifecycle.LifecycleOwner
Any ideas?
public class CompanyMV extends AndroidViewModel{
public CompanyMV(Application application) {
super(application);
repo.getNumbers(this.ID).observe(application, new Observer<Integer>() {
@Override
public void onChanged(@Nullable Integer number) {
}
});
}
observe()
is for use by activities, fragments, and other things with a discrete lifecycle. An Application
does not have that — it lives as long as your process does.
Use observeForever()
instead of observe()
here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With