I've created a custom Preference
ClickPreference
:
class ClickPreference(context: Context, attrs: AttributeSet) : Preference(context, attrs), View.OnClickListener {
override fun onBindViewHolder(holder: PreferenceViewHolder?) {
super.onBindViewHolder(holder)
val box = holder?.itemView
box?.setOnClickListener(this)
}
override fun onClick(v: View?) {
action(title)
}
fun action(title: CharSequence){
when (title){
"email" -> {
...
}
"Logout" -> {
LoginManager.getInstance().logOut()
val intent = Intent(context, MainActivity::class.java) // context is from getContext()
startActivity(intent)
}
}
}
}
However I'm getting this error on startActivity()
:
I don't understand why it's wrong as it's a valid Intent
constructor.
Any idea?
Try this:
val intent = Intent(context, MainActivity::class.java)
context.startActivity(intent)
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