Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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
Android UI Development with Jetpack Compose

You're reading from   Android UI Development with Jetpack Compose Bring declarative and native UI to life quickly and easily on Android using Jetpack Compose and Kotlin

Arrow left icon
Product type Paperback
Published in Nov 2023
Publisher Packt
ISBN-13 9781837634255
Length 278 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Thomas Künneth Thomas Künneth
Author Profile Icon Thomas Künneth
Thomas Künneth
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Part 1: Fundamentals of Jetpack Compose FREE CHAPTER
2. Chapter 1: Building Your First Compose App 3. Chapter 2: Understanding the Declarative Paradigm 4. Chapter 3: Exploring the Key Principles of Compose 5. Part 2: Building User Interfaces
6. Chapter 4: Laying Out UI Elements in Compose 7. Chapter 5: Managing State of Your Composable Functions 8. Chapter 6: Building a Real-World App 9. Chapter 7: Exploring App Architecture 10. Part 3: Advanced Topics
11. Chapter 8: Working with Animations 12. Chapter 9: Exploring Interoperability APIs 13. Chapter 10: Testing and Debugging Compose Apps 14. Chapter 11: Developing for Different Form Factors 15. Chapter 12: Bringing Your Compose UI to Different Platforms 16. Index 17. Other Books You May Enjoy

Understanding side effects

In the Using Scaffold() to structure your screen section of Chapter 6, Building a Real-World App, I showed you how to display a snack bar using rememberCoroutineScope {} and snackbarHostState.showSnackbar(). As showSnackbar() is a suspending function, it must be called from a coroutine or another suspending function. Therefore, we created and remembered CoroutineScope using rememberCoroutineScope() and invoked its launch {} function.

Invoking suspending functions

The LaunchedEffect() composable is an alternative approach for spawning a suspending function. To see how it works, let’s look at the LaunchedEffectDemo() composable. It belongs to the EffectDemo example, as illustrated in the following screenshot:

Figure 7.1 – The EffectDemo example showing LaunchedEffectDemo()

Figure 7.1 – The EffectDemo example showing LaunchedEffectDemo()

LaunchedEffectDemo() implements a counter. Once the Start button has been clicked, a counter is incremented every second. Clicking on Restart...

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 $19.99/month. Cancel anytime