https://kotlinlang.org logo
#android
Title
# android
m

mhamade

11/03/2019, 3:24 AM
Is it better to do this:
context.getSystemService(VIBRATOR_SERVICE) as Vibrator
or
context.getSystemService(VIBRATOR_SERVICE) as? Vibrator
t

tseisel

11/03/2019, 8:18 AM
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

Luca Nicoletti

11/03/2019, 8:19 AM
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

mhamade

11/03/2019, 9:27 PM
Thank you
l

louiscad

11/04/2019, 9:31 AM
It's better to do
vibrator
using #splitties System Services artifact (available in top-level) in my humble and biased opinion.
41 Views