Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot access androidx.lifecycle.LifecycleOwner, what is the meaning of error in Android?

On which situation android-build/android-studio shows these errors?

Cannot access androidx.lifecycle.LifecycleOwner and
Cannot access androidx.lifecycle.ViewModelStoreOwner

What is the meaning of this errors? I found that adding androidx.lifecycle:lifecycle-viewmodel as dependency solves these errors, I want to know the meaning of the error in terms of Android Activity LifeCycle(Or is it related to lifecycle or not).

For example in this code call to `super' onSavedInstanceState shows this error

public class AppActivity extends FragmentActivity {

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);  // Cannot access androidx.lifecycle.LifecycleOwner
    }

}

When should I use Android Lifecycles,and when should I avoid using it?

like image 994
LaraFlow Avatar asked Sep 02 '19 20:09

LaraFlow


2 Answers

add this to your gradle dependencies

implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
like image 159
rham Avatar answered Sep 28 '22 17:09

rham


Update to the latest appcompat library version can help with this.

androidx.appcompat:appcompat:1.3.0-alpha01
like image 38
serhii Avatar answered Sep 28 '22 18:09

serhii