Type mismatch: inferred type is LoginActivity but LifecycleOwner was expected
It seems androidx.appcompat.app.AppCompatActivity
doesn't implement LifecycleOwner
interface in the version you are using androidx.appcompat:appcompat:1.0.2.
android.support.v7.app.AppCompatActivity
implicitly implements LifecycleOwner
, so you need to inherit from it instead of androidx.appcompat.app.AppCompatActivity
:
class LoginActivity : android.support.v7.app.AppCompatActivity() { ... }
or use some other Activity
class that implements (explicitly or implicitly) LifecycleOwner
, e.g. android.support.v4.app.FragmentActivity
.
Additionally, any custom application class can implement the LifecycleOwner
interface. More info about LifecycleOwner
is here.
If you are using androidx.appcompat:appcompat:1.0.2
It won't work for you as LifeCycleOwner is not implemented. Your AppCompatActivity extends FragmentActivity which further extends ComponentActivity and ComponentActivity implements LifeCycleOwner which is not in 1.0.2 version so upgrading (1.1.0-alpha02) or downgrading (1.0.0) will work for you.
Happy coding :)
I had the same issue and fix it with updating my support version to
versions.support = "1.1.0-alpha01"
so which means just update the
implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
and it should be fixed