Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
How to Build Android Apps with Kotlin

You're reading from   How to Build Android Apps with Kotlin A hands-on guide to developing, testing, and publishing your first apps with Android

Arrow left icon
Product type Paperback
Published in Feb 2021
Publisher Packt
ISBN-13 9781838984113
Length 794 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (4):
Arrow left icon
Eran Boudjnah Eran Boudjnah
Author Profile Icon Eran Boudjnah
Eran Boudjnah
Jomar Tigcal Jomar Tigcal
Author Profile Icon Jomar Tigcal
Jomar Tigcal
Alex Forrester Alex Forrester
Author Profile Icon Alex Forrester
Alex Forrester
Alexandru Dumbravan Alexandru Dumbravan
Author Profile Icon Alexandru Dumbravan
Alexandru Dumbravan
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface
1. Creating Your First App 2. Building User Screen Flows FREE CHAPTER 3. Developing the UI with Fragments 4. Building App Navigation 5. Essential Libraries: Retrofit, Moshi, and Glide 6. RecyclerView 7. Android Permissions and Google Maps 8. Services, WorkManager, and Notifications 9. Unit Tests and Integration Tests with JUnit, Mockito, and Espresso 10. Android Architecture Components 11. Persisting Data 12. Dependency Injection with Dagger and Koin 13. RxJava and Coroutines 14. Architecture Patterns 15. Animations and Transitions with CoordinatorLayout and MotionLayout 16. Launching Your App on Google Play

Coroutines

Coroutines were added in Kotlin 1.3 for managing background tasks such as making network calls and accessing files or databases. Kotlin coroutines are Google's official recommendation for asynchronous programming on Android. Their Jetpack libraries, such as LifeCycle, WorkManager, and Room, now include support for coroutines.

With coroutines, you can write your code in a sequential way. The long-running task can be made into a suspending function, which when called can pause the thread without blocking it. When the suspending function is done, the current thread will resume execution. This will make your code easier to read and debug.

To mark a function as a suspending function, you can add the suspend keyword to it; for example, if you have a function that calls the getMovies function, which fetches movies from your endpoint and then displays it:

val movies = getMovies()
displayMovies(movies) 

You can make the getMovies() function a suspending function...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime