Modern Android development: Android Jetpack, Kotlin, and more (Google I/O 2018)

Android Developers · 127K views · 2018 · 39:17

Open on YouTube

Software architecture & designSoftware performance & optimizationSoftware practice, open source & careerstalkdated

Why Stack Overflow recommends it

Stack Overflow users link it as an official Google source showing that enums are no longer a performance problem on Android with ART, and as guidance on modern Android practices.

Recommended by 5 people across 5 different months, 2018 to 2021.

What it is

A Google I/O 2018 session from the Android Developers channel explaining how Jetpack, Kotlin and the newer Android APIs fit together, and when to use them instead of older approaches. It covers modern app architecture and platform guidance, including a segment on runtime performance with ART.

What people said

Recommends Oz Shabat · 2018-05 · Stack Overflow · on “How to use Android Support typedef annotations in kotlin?”

Update: Forget @IntDef and @StringDef, Now, with ART, you can use enums instead. From the official GoogleIO: [this video] Plus, if you're still not sure if you should use enums, you can hear a bunch of people yelling at each other in the comments of the first answer over here: [LINK] Old answer: Just create the @IntDef class as a java class and access it via kotlin code. Example: Create your type class: public class mType { @IntDef({typeImpl.type1, typeImpl.type2, typeImpl.type3}) @Retention(RetentionPolicy.SOURCE) public @interface typeImpl { int type1 = 0; int type2 = 1; int type3 = 2; } } Put this function in any Kotlin object: object MyObject{ fun accessType(@mType.typeImpl mType: Int) { ...

Recommends Rambo7 · 2019-01 · Stack Overflow · on “Kotlin enum class in Android performance”

You can most definitely use enums in Android now , they specifically discussed this topic in this Google I/O video: [this video] (if you don't want to watch the whole video, then start from 11:30 ish to 14:40).

Recommends Clément Jean · 2020-04 · Stack Overflow · on “Which programming language is recommended for android development? Kotlin OR Java?”

Google is going kotlin-first in its documentation, even saying that you "Write better Android apps faster with Kotlin" [LINK] . So you should be using Kotlin. Furthermore Kotlin has some advantages: less verbose strong interoperability with Java (you can still use java libraries) Coroutines ( Improve app performance with Kotlin coroutines [LINK] ) But of course, you will find less tutorial than in Java on certain topics (but it will catch up, the community is growing fast). Edit 2021/03/09 Another reason you might consider Kotlin for android is the kotlin extension for gradle which provide auto-completion and an object like approach in configuration files. You can find a few resources here [

Recommends Iulian Popescu · 2020-06 · Stack Overflow · on “How to set a view at specific position on screen?”

Android had a layout [LINK] that would support this requirements, but I think that it was pretty bad in regards to performance and it was deprecated (I hope that I am not wrong making this affirmation). However, the same behaviour can be implemented using a FrameLayout and add the views in that layout. To add a view at a particular position, you create its layout params to set a width and a height, then set the margins which will position your view as absolute coordinates (the dimension is in pixels): val imageView = ImageView(this) imageView.setBackgroundResource(android.R.color.holo_red_dark) imageView.layoutParams = FrameLayout.LayoutParams(width, height).apply { setMargins(left, top, rig

Recommends César Muñoz · 2021-03 · Stack Overflow · on “How to replace enum in Android?”

Enums are no longer an issue for Android thanks to the replacement of Dalvik as runtime environment by ART. You can find more information about it in this Google IO video from 2018: [this video] - If you don't want to watch the whole vid you can fast forward to the minute 14:09. Plus, thanks to R8, most enums are optimised at compile time too: [LINK] So go ahead and your Enums :) they make the code more concise, easier to understand and less error-prone than other options.

Cites MD Naseem Ashraf · 2019-03 · Stack Overflow · on “Textview and button inside the relativelayout not get visible in android oreo and pie but visible in other android version perfectly”

Your xml screenshots were painful to read but, I just realized you're using fill_parent instead of match_parent . FILL_PARENT is deprecated in API 8 afterwards; Google Developer Documentation Source [LINK] . Why you should use Match Parent [LINK] . Maybe it's time you moved towards the more recently introduced methods, design patterns and libraries. Start using Constraint Layout instead of Relative Layout. Benefits of Constraint Layout [LINK] and its introduction in Android Studio 2.2 [LINK] onwards. Stop using Relative Layouts and use them only when very necessary. Google I/O Talk of 2018 on Layouts, Link [this video] . You don't know when Google will decide to deprecate it and then you'd have p

Cites Rajan Kali · 2021-02 · Stack Overflow · on “Restricting values in parameters via annotations Kotlin”

Firstly, it is not Kotlin compiler which checks for this type of annotation errors, Android Lint does, also this might work and preferred over enums in Java , but in Kotlin , the only way to do these are using enums , You can still use @IntDef in Kotlin to provide suggestions but other values won't give you a compile error. Also with ART, mem footprint for enums are not a big deal, this was also covered in Google IO 2018 while talking about ART [this video]

Cites Jayanth · 2021-08 · Stack Overflow · on “What to use instead of this enum?”

You can now use Enums in Android. It doesn't affect that much on performance in ART. It was discussed in the Google I/O You can refer the here in Video Google IO SpeedLink to Enum topic [this video] If you want an alternate for enum in Kotlin, of course, you can always use Sealed classes. This is how it looks in sealed class //Enum version enum class Heroes( val heroName: String, val heroLevel: Int, val healthPoints: Int, val xpMultipleMax: Double ) { GLAZIER("Glazier", 1, 25, 1.2), ONYX("Onyx", 2, 35, 1.3), PARDUS("Pardus", 3, 50, 1.5), EAGLE_EYE("Eagle eye", 4, 70, 1.7), TORNADO("Tornado", 5, 100, 2.0) } //sealed class verison sealed class Heroes( val heroName: String, val heroLevel: Int, val h

Cites Hayk Mkrtchyan · 2021-08 · Stack Overflow · on “What to use instead of this enum?”

Regarding many references in the network, I've found that using enum in android affects the performance badly. So for simpler int or String enums, they recommend using an annotation library @TypeDef . But what if I have an enum like this? enum class Heroes( val heroName: String, val heroLevel: Int, val healthPoints: Int, val xpMultipleMax: Double ) { GLAZIER("Glazier", 1, 25, 1.2), ONYX("Onyx", 2, 35, 1.3), PARDUS("Pardus", 3, 50, 1.5), EAGLE_EYE("Eagle eye", 4, 70, 1.7), TORNADO("Tornado", 5, 100, 2.0) } Is it possible to apply the @TypeDef here? And I think in this case even R8 and Proguard can't help because as I know they just help to convert the enum to int . But how they will convert i