I'm trying to add an onPreferenceClickListener within my SettingsFragment and if I do it like this:
signOutPref.setOnPreferenceClickListener(object: Preference.OnPreferenceClickListener {
override fun onPreferenceClick(preference: Preference?): Boolean {
val signOutIntent = Intent(activity, SignInActivity::class.java)
startActivity(signOutIntent)
return true
}
})
It works perfectly while giving a warning:
Use property access syntax
While if I write it like this:
signOutPref.setOnPreferenceClickListener {
val signOutIntent = Intent(activity, SignInActivity::class.java)
startActivity(signOutIntent)
return true
}
which should be the exactly the same thing and it's the best way to do it, I get a:
The Boolean literal does not conform to the expected type Unit
on the return true
statement.
What am I missing? Is the second way to do it different than the first? How do I get rid of this error?