Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Beyond Java, Exploring the Modern Android Development

Beyond Java, Exploring the Modern Android Development

Dive into the Future of App Development: Master Kotlin, Jetpack Compose, and Production-Ready Techniques!

Bhoomi Vaghasiya Gadhiya

January 10, 2024
Tweet

Transcript

  1. About me 󰟲 • Android Developer • Technical Author in

    DroidCon Academy • Technical Blogger : Medium @bhoomigadhiya • Technical Speaker in community • Empowering Women In Tech
  2. XML + Java XML + Kotlin Jetpack Compose In Kotlin

    Evolution Of Android Development
  3. • Developed By Jetbrains JetBrains is a software development company

    that creates intelligent development tools for software developers and project managers.
  4. • 2016 - Kotlin 1.0 released • 2017 - Android

    announced Official support for Kotlin
  5. Data Classes public class User { String name; int age;

    public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } data class User(var name:String,var age:Int) KOTLIN JAVA
  6. Tony’s $1B Mistake “I call it my billion-dollar mistake. It

    was the invention of the null reference in 1965…This has led to innumerable errors, vulnerabilities, and system crashes,” - Tony Hoare
  7. Null-Safety ./No Compiler Error String name = null; ./Compiler Error

    var name:String = null KOTLIN JAVA ./No Compiler Error var name:String? = null ./Compiler Error on line 2 var nameLength = name.length ./Runtime Error int nameLength = name.length()
  8. Functional Programming • Immutable Data • High-Order functions • Lambda

    Expressions • Extension function • And much more!
  9. Jetpack Compose? • Modern UI toolkit for building native UI

    • Entirely built in Kotlin • Do more with Less Code
  10. Jetpack Compose? • Modern UI toolkit for building native UI

    • Entirely built in Kotlin • Do more with Less Code • Intuitive Kotlin APIs
  11. Jetpack Compose? • Modern UI toolkit for building native UI

    • Entirely built in Kotlin • Do more with Less Code • Intuitive Kotlin APIs • Accelerate Development
  12. Jetpack Compose? • Modern UI toolkit for building native UI

    • Entirely built in Kotlin • Do more with Less Code • Intuitive Kotlin APIs • Accelerate Development • Powerful Tool
  13. Composable • A function that is used to create a

    UI element in Jetpack Compose. • Focuses on “What” rather “How”
  14. Jetpack Compose View ./MainActivity.kt class MainActivity : Activity() { override

    fun onCreate(...) { setContentView(R.layout.activity_main) } } ./activity_main.xml <LinearLayout...> <TextView ... android:text="Hello World" .> ./LinearLayout> ./MainActivity.kt class MainActivity : Activity() { override fun onCreate(...) { setContent{ Greeting() } } } @Composable fun Greeting(){ Text("Hello World") }
  15. Button @Composable fun Demo() { Button(onClick = { ** Do

    Something */ }) { Text("Click Me") } }
  16. Box @Composable fun Demo() { Box(Modifier.size(28.dp)) { Text("A", modifier =

    Modifier.align(Alignment.TopStart)) Text("B", modifier = Modifier.align(Alignment.Center)) Text("C", modifier = Modifier.align(Alignment.BottomEnd)) } } A B C
  17. Modifier • Change the appearance and behavior of composables. •

    Example: setting background color, adding padding, making elements clickable, and more.
  18. Modifier @Composable fun Demo() { Box(Modifier.background(Color.Yellow)) { Text( text =

    "Hello", modifier = Modifier .padding(8.dp) .background(Color.Red) ) } } Hello
  19. State • State is any value in the app that

    can change. • Examples: a. Whether to show a button or not based on some condition. b. Result of fetching the data : Loading, Error, Success. c. Error message when user enters invalid message.
  20. @Composable fun DisplayName(name: String) { Text(text = "Hello, $name!") }

    Initial Composition @Composable fun DisplayName(name: String) { Text(text = "Hello, $name!") } Name Changes ReComposition Recomposition
  21. Recomposition • Whenever state is updated, recomposition takes place. •

    Only way to update UI, calling same composable with new argument.
  22. Recomposition • Whenever state is updated, recomposition takes place. •

    Only way to update UI, calling same composable with new argument. • Only rebuild part of UI.
  23. Remember @Composable fun Detail(name: String) { val someClass = SomeClass()

    Text(name) } Without Remember With Remember @Composable fun Detail(name: String) { val someClass = remember{SomeClass()} Text(name) } val someClass Composition 1 Recomposition 2 Recomposition 3 SomeClass@111 SomeClass@222 SomeClass@333 val someClass Composition 1 Recomposition 2 Recomposition 3 SomeClass@111 SomeClass@111 SomeClass@111
  24. How to create State? var enabled by remember { mutableStateOf(true)

    } Retain the data during recomposition Store the latest value
  25. Want to learn Compose? • developer.android.com/jetpack/compose • github.com/android/compose-samples • github.com/android/nowinandroid

    • medium.com/androiddevelopers • youtube.com/c/AndroidDevelopers/videos • composables.com • youtube.com/@CheezyCode
  26. Architecture Patterns • MVC (Model - View - Controller) •

    MVP (Model - View - Presenter) • MVVM (Model - View - ViewModel) • MVI (Model - View - Intent) • And some more!
  27. Firebase • BAAS (Backend As A Service) • Build, improve

    and grow your app • No need to maintain the server!