You're defining the ClarifaiManager as nullable aswel as making it mutable in your Activity with var manager: ClarifaiManager? = null and then initialize it in your onCreate.
Imo, there's a better way so that you don't have to mark it as nullable and have it immutable with the following code:
val manager: ClarifaiManager by lazy { ClarifaiManager(this, getString(R.string.api_id), getString(R.string.api_secret)) }
The val makes sure it's immutable, ClarifaiManager without a question mark makes sure it's never null and by lazy is gonna run the initialization code behind it the first time it's requested.
Wow, that's a great recommendation, thank you so much! I didn't realize Kotlin had the lazy property until your comment. More on that here - kotlinlang.org/docs/reference/dele...
I will try to make this update later today.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You're defining the ClarifaiManager as nullable aswel as making it mutable in your Activity with
var manager: ClarifaiManager? = null
and then initialize it in youronCreate
.Imo, there's a better way so that you don't have to mark it as nullable and have it immutable with the following code:
val manager: ClarifaiManager by lazy { ClarifaiManager(this, getString(R.string.api_id), getString(R.string.api_secret)) }
The
val
makes sure it's immutable,ClarifaiManager
without a question mark makes sure it's never null andby lazy
is gonna run the initialization code behind it the first time it's requested.I've made the change. Thanks again!
Wow, that's a great recommendation, thank you so much! I didn't realize Kotlin had the
lazy
property until your comment. More on that here - kotlinlang.org/docs/reference/dele...I will try to make this update later today.