Is it better to do this: `context.getSystemService...
# android
m
Is it better to do this:
context.getSystemService(VIBRATOR_SERVICE) as Vibrator
or
context.getSystemService(VIBRATOR_SERVICE) as? Vibrator
t
How about
context.getSystemService<Vibrator>()
, available in androidx.core ? Note that the first alternative will crash the app if the returned object is not a Vibrator or if it is null (which is very unlikely since the vibrator service exists since API 1)
👍 2
l
You never know what manifacturers will stop shipping on devices 🧌
😂 1
Always fo with the safest way 🙂 which in this case is the one @tseisel posted
or
context.getSystemService(VIBRATOR_SERVICE) as? Vibrator
the second one
m
Thank you
l
It's better to do
vibrator
using #splitties System Services artifact (available in top-level) in my humble and biased opinion.