Android Development with Kotlin — Jake Wharton

Android KW · 114K views · 2015 · 36:59

Open on YouTube

Programming language designSoftware practice, open source & careerstalkdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering Kotlin-on-Android questions, as an early authoritative walkthrough of Anko-style DSLs and extension functions.

Recommended by 2 people across 2 different months, 2016 to 2018.

What it is

Jake Wharton's 2015 meetup talk on using Kotlin for Android development, aimed at moving past introductory material to design patterns and larger-scale usage. It covers idiomatic uses such as extension functions and DSLs, with a SharedPreferences extension example near the end, and is useful to any Java developer curious about Kotlin.

What people said

Recommends nPn · 2016-02 · Stack Overflow · on “Is it possible to use Java 8 for Android development?”

When I asked this question almost 2 years ago the answer really was “officially” no, but as pointed out by ekcr1's answer you can get one of the most highly anticipated features (lambdas) to work if you use retrolamba. At the time I was still using eclipse, as Android Studio was in “preview” mode, so I never did pursue this path. Today, I think the “official” answer is still no, and while retrolamba still seems like a good way to go, there is another option for those willing to go down a somewhat “unofficial” route can take, namely Kotlin. Today Kotlin reached 1.0.0. For those not familiar with Kotlin, more info can be found at their website found here: [LINK] or watch this utube video of a

Recommends Gary Lee · 2016-09 · Stack Overflow · on “Context issue when using Anko DSL within customized adapter for ListView”

According to this video [this video] , here is the modified version: class AnkoAdapter<T>(itemFactory: () -> List<T>, viewFactory: Context.(index: Int, items: List<T>, view: View?) -> View): BaseAdapter() { val viewFactory = viewFactory val items: List<T> by lazy { itemFactory() } override fun getView(index: Int, view: View?, viewGroup: ViewGroup?): View { return viewGroup!!.context.viewFactory(index, items, view) } override fun getCount(): Int { return items.size } override fun getItem(index: Int): T { return items.get(index) } override fun getItemId(index: Int): Long { return (items.get(index) as Any).hashCode().toLong() + (index.toLong() * Int.MAX_VALUE) } } val items = listOf<String>("Mary",

Cites flopshot · 2018-02 · Stack Overflow · on “Kotlin extension field for SharedPreference value by string constant key”

Extension functions are great for the SharedPreference api in android. Jake Wharton has an interesting implementation at time code 32:30 of this [this video] video tutorial where he implements SharedPreferences extension function like so: preferences.edit{ set(USER_ID /*some string key constant somewhere*/, 42) //... } while this is ok, its kind of verbose. This [LINK] tutorial by Krupal Shah explains how you can reduce the getter/setter extension functions of SharedPreferences to: preferences[USER_ID] = 42 Log.i("User Id", preferences[USER_ID]) //User Id: 42 This is pretty good, but the brackets imply iterable semantics, IMO. While not the worst thing in the world, you just wish that you could i