Kotlin’s List missing “add”, “remove”, Map missing “put”, etc?

In Java we could do the following public class TempClass { List<Integer> myList = null; void doSomething() { myList = new ArrayList<>(); myList.add(10); myList.remove(10); } } But if we rewrite it to Kotlin directly as below class TempClass { var myList: List<Int>? = null fun doSomething() { myList = ArrayList<Int>() myList!!.add(10) myList!!.remove(10) } } I … Read more

Warning “Kotlin plugin version is not the same as library version” (but it is!)

I have an Android studio project in which I have added a Java library module, which I call core. My three Gradle build files look like this. project/build.gradle buildscript { ext.kotlin_version = ‘1.2.40’ repositories { google() jcenter() } dependencies { classpath ‘com.android.tools.build:gradle:3.0.1’ classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version” } } allprojects { repositories { google() jcenter() } } task … Read more

startForeground fail after upgrade to Android 8.1

After upgrading my phone to 8.1 Developer Preview my background service no longer starts up properly. In my long-running service I’ve implemented a startForeground method to start the ongoing notification which is called in on create. @TargetApi(Build.VERSION_CODES.O) private fun startForeground() { // Safe call, handled by compat lib. val notificationBuilder = NotificationCompat.Builder(this, DEFAULT_CHANNEL_ID) val notification … Read more