Smart cast to ‘Type’ is impossible, because ‘variable’ is a mutable property that could have been changed by this time

Between execution of left != null and queue.add(left) another thread could have changed the value of left to null. To work around this you have several options. Here are some: Use a local variable with smart cast: val node = left if (node != null) { queue.add(node) } Use a safe call such as one … Read more

Alarm Manager Example

This is working code. It wakes CPU every 10 minutes until the phone turns off. Add to Manifest.xml: … <uses-permission android:name=”android.permission.WAKE_LOCK”></uses-permission> … <receiver android:process=”:remote” android:name=”.Alarm”></receiver> … Code in your class: package yourPackage; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.PowerManager; import android.widget.Toast; public class Alarm extends BroadcastReceiver { @Override public void … Read more

How to make an Android device vibrate? with different frequency?

Try: import android.os.Vibrator; … Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 500 milliseconds if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE)); } else { //deprecated in API 26 v.vibrate(500); } Note: Don’t forget to include permission in AndroidManifest.xml file: <uses-permission android:name=”android.permission.VIBRATE”/>

How to check if a “lateinit” variable has been initialized?

There is a lateinit improvement in Kotlin 1.2 that allows to check the initialization state of lateinit variable directly: lateinit var file: File if (this::file.isInitialized) { … } See the annoucement on JetBrains blog or the KEEP proposal. UPDATE: Kotlin 1.2 has been released. You can find lateinit enhancements here: Checking whether a lateinit var … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)