Slide 1

Slide 1 text

This work is licensed under the Apache 2.0 License Android Study Jams Modern Android Development

Slide 2

Slide 2 text

This work is licensed under the Apache 2.0 License Modern Android Development Pre-requisites Coroutines MotionLayout Using Hilt in your Android App Learn the more advanced techniques of building Android apps using libraries, testing, Jetpack and more to increase the quality of your app ● Finished the First Two Tracks Curriculum used Advanced WorkManager Advanced Testing : Survey of Testing Topics Jetpack Compose Basics

Slide 3

Slide 3 text

This work is licensed under the Apache 2.0 License What will you learn? 2 3 1 Coroutines MotionLayout (1 hour) (1 hour) Coroutines are a Kotlin feature that converts async callbacks for long-running tasks, such as database or network access, into sequential code. MotionLayout is a library that lets you add rich motion into your Android app. Modern Android Development Using Hilt in your Android Apps (1 hour) Learn the importance of dependency injection (DI) to create a solid and extensible application that scales to large projects. We'll use Hilt as the DI tool to manage dependencies.

Slide 4

Slide 4 text

This work is licensed under the Apache 2.0 License 5 Advanced Testing: Survey of Topics Learn Coroutines, Room, Databinding and End-to-End Testing. 6 Jetpack Compose Basics Learn Coroutines, Room, Databinding and End-to-End Testing. 4 Advanced WorkManager (1 hour) Teaches advanced WorkManager concepts. It builds on the basic material covered in the Background Work with WorkManager codelab. What will you learn? Modern Android Development (2 hour) (1 hour)

Slide 5

Slide 5 text

This work is licensed under the Apache 2.0 License Android Study Jams Modern Android Development Coroutines

Slide 6

Slide 6 text

This work is licensed under the Apache 2.0 License TOPIC DATE Intro Coroutine Sept 22 Return on Coroutine and intro to MotionLayout Sept 29 Return on MotionLayout and intro Using Hilt in your Android Apps Oct 6 Return on Hilt and intro to Advanced WorkManager Oct 13 Return on Advanced WorkMananger and intro to Advanced Testing: Survey of Topics Oct 20 Return on Advanced Testing and intro to Jetpack Compose Basics Oct 27 Return on Jetpack Compose Basics and thank you Nov 3 Android study Jam Schedule

Slide 7

Slide 7 text

This work is licensed under the Apache 2.0 License Modern Android Development : Coroutines Android Study Jams

Slide 8

Slide 8 text

This work is licensed under the Apache 2.0 License Learning Objectives ० Understand how to use coroutine. ० Use suspend functions to make async code sequential. ० Use launch and runBlocking to control how code executes. ० Learn techniques to convert existing APIs to coroutines using suspendCoroutine. ० Use coroutines with Architecture Components. ० Learn best practices for testing coroutines.

Slide 9

Slide 9 text

This work is licensed under the Apache 2.0 License ० Familiarity with the Architecture Components ViewModel, LiveData, Repository, and Room. ० Experience with Kotlin syntax, including extension functions and lambdas. ० A basic understanding of using threads on Android, including the main thread, background threads, and callbacks. ० Android Studio 4.1 Prerequisites

Slide 10

Slide 10 text

This work is licensed under the Apache 2.0 License Concept Overview What is Coroutine?

Slide 11

Slide 11 text

This work is licensed under the Apache 2.0 License The word “coroutine” is composed of two words: “co” (cooperative) and “routines” (functions). Coroutines are functions that are cooperative. Source : https://www.educative.io/edpresso/what-is-a-coroutine

Slide 12

Slide 12 text

This work is licensed under the Apache 2.0 License How are functions non-cooperative? Source : https://www.educative.io/edpresso/what-is-a-coroutine Usually, when a function calls a second function, the first cannot continue until the second function finishes and returns to where it was called.

Slide 13

Slide 13 text

This work is licensed under the Apache 2.0 License How can functions cooperate with one another? Coroutines are functions where the control is transferred from one function to the other function in a way that the exit point from the first function and the entry point to the second function are remembered – without changing the context. Source : https://www.educative.io/edpresso/what-is-a-coroutine

Slide 14

Slide 14 text

This work is licensed under the Apache 2.0 License // Async callback networkRequest { result -> // Successful network request databaseSave(result) { row-> } } // The same code with coroutine val result = networkRequest() // Successful network request databaseSave(result) // Result saved SEQUENTIAL ASYNC

Slide 15

Slide 15 text

This work is licensed under the Apache 2.0 License ० Replace callbacks by sequential programming ० Ability to make your call main safe with suspend ( in Android ) Advantage of Coroutines

Slide 16

Slide 16 text

This work is licensed under the Apache 2.0 License Some basic tips

Slide 17

Slide 17 text

This work is licensed under the Apache 2.0 License You can see suspend function in Android studio

Slide 18

Slide 18 text

This work is licensed under the Apache 2.0 License “Exceptions in suspend functions work just like errors in regular functions. If you throw an error in a suspend function, it will be thrown to the caller.”

Slide 19

Slide 19 text

This work is licensed under the Apache 2.0 License “The suspend keyword doesn't specify the thread code runs on. Suspend functions may run on a background thread or the main thread.”

Slide 20

Slide 20 text

This work is licensed under the Apache 2.0 License “To switch between any dispatcher, coroutines uses withContext.”

Slide 21

Slide 21 text

This work is licensed under the Apache 2.0 License “In Kotlin, all coroutines run inside a CoroutineScope”

Slide 22

Slide 22 text

This work is licensed under the Apache 2.0 License What you’ll do ● Use suspend functions to make async code sequential ● Use launch and runBlocking to control how code executes. ● Convert APIs to coroutines using suspendCoroutine ● Best practices for testing

Slide 23

Slide 23 text

This work is licensed under the Apache 2.0 License Let’s get started

Slide 24

Slide 24 text

This work is licensed under the Apache 2.0 License Start here: https://developer.android.com/codelabs/kotlin-coroutines#0 Collect your badges!

Slide 25

Slide 25 text

This work is licensed under the Apache 2.0 License Carrie Sawyer Build Your First App Pathway Build an Interactive App Layouts Pathway Create a Developer Profile

Slide 26

Slide 26 text

This work is licensed under the Apache 2.0 License Share what you’ve learned with #AndroidStudyJams

Slide 27

Slide 27 text

This work is licensed under the Apache 2.0 License Have a Question? Just ask Join our slack : bit.ly/gdgmontrealslack Joins our channel : #android-study-jams-2021

Slide 28

Slide 28 text

This work is licensed under the Apache 2.0 License Start here: https://developer.android.com/codelabs/kotlin-coroutines#0 Collect your badges!

Slide 29

Slide 29 text

This work is licensed under the Apache 2.0 License Welcome back And congrats!

Slide 30

Slide 30 text

This work is licensed under the Apache 2.0 License Recap of Coroutines ० suspend ० Coroutine inside a viewModel ० Main Safe ० Cancel all coroutines in viewModel ० Coroutine with WorkManager ० Higher order function ० Moving callback to coroutine ० Testing

Slide 31

Slide 31 text

This work is licensed under the Apache 2.0 License Learn More

Slide 32

Slide 32 text

This work is licensed under the Apache 2.0 License Want to learn more about coroutine? ● Check out the " Advanced Coroutines with Kotlin Flow and LiveData" codelab to learn more advanced coroutines usage on Android. ● Cancellation and exceptions : Part 1: Coroutines, Part 2: Cancellation in coroutines, and Part 3: Exceptions in coroutines. ● Coroutine guides by JetBrains ● "Improve app performance with Kotlin coroutines" for more usage patterns of coroutines on Android. ● WorkManager Version 1.0

Slide 33

Slide 33 text

This work is licensed under the Apache 2.0 License Want to learn more? ● Official Android Developers Site: https://developer.android.com/ ● Android Samples on GitHub ● Official Android Developers Blog (for announcements) ● Android Developers Medium Blog (for more technical articles) ● Android Developers YouTube channel ● Follow @AndroidDev on Twitter ● Subscribe to the Android Developer Newsletter ● Official Kotlin language site Version 1.0