versionCode vs versionName in Android Apps

versionCode 1versionName “0.1” versionName is a string which is visible to the user in the settings menu under App Info versionCode is an integer. It is used to compare APK updates against each other to make sure apps aren’t downgraded. val packageInfo: PackageInfo = this.packageManager.getPackageInfo(this.packageName, 0)Log.d(packageInfo.versionName)Log.d(packageInfo.versionCode) Further Reading Anatomy of a Gradle file Depdencency Graph…

Logging in Android

Logging brings some light into the darkness of your code. If you are new to logging please have a look at Log4j2 for Kotlin Import import android.util.Log Tag class MainActivity : AppCompatActivity() { companion object { const val TAG = “MainActivity” } Log statement override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) Log.d(TAG, “onCreate”) } Logcat Further…

Classes in Kotlin – Part 2

In Part 1 we dealt with the simplest form of initialization with the primary constructor: class Planet( val diameter: Int, val distanceToSun: Double, val mass: Double ) But wait: there is more: Init block The primary constructor cannot contain any code so init block for the rescue: class Planet( val diameter: Int, val distanceToSun: Double,…

Classes in Kotlin – Part 1

Why is there a car in the picture? – Because it has class! Jokes aside, classes are still the building blocks of modern object oriented software design. And of course as the new kid on the block Kotlin has it’s own take on this subject. Declaration Let’s look at the most basic class declaration: class…

Kotlinx Datetime

Dependency Add the following to your dependencies implementation(org.jetbrains.kotlinx:kotlinx-datetime:0.2.0) Usage import kotlinx.datetime.* val today = Clock.System.todayAt(TimeZone.currentSystemDefault()) If you target Android devices running below API 26, you need to use Android Gradle plugin 4.0 or newer and enable core library desugaring. https://github.com/Kotlin/kotlinx-datetime