‫Hello, my friends.
‫In this video, I'm going to challenge you in a coroutine application.
‫So I want from you to create a new project, empty Activity, and I will name it as challenge or coroutine
‫app to or you can make it as challenge coding.
‫Challenge number one.
‫Okay.
‫Let's add the dependency for the Coroutines in the build.gradle.
‫And after that, I will tell you what I need from you to make.
‫Okay, so this is our dependency and I can change it to 1.6, point one click sync now and everything
‫will work fine.
‫Now let's move to the main activity here and I will go to the split mode.
‫I will change this text to co routine app number two and the size would be 32 sp okay now.
‫I will add two text views.
‫Wrap content.
‫Wrap content ID would be.
‫At ID text one and size would be 32 sp.
‫And this is good text would be.
‫Text one.
‫Okay.
‫And the second text would be.
‫The same.
‫Copy it.
‫And here we go.
‫Text number two.
‫This is text number two.
‫And here, text number two.
‫Okay.
‫So you can change text number one.
‫And text number two, I want from you to run.
‫A hello message and display a low message here from the main thread and in the text number two, I want
‫from you to display a hello message from the.
‫Background thread.
‫Okay, so please post the video and think about this challenge.
‫How to display a hello message inside this text from the main thread and this text from the background
‫thread.
‫So pause the video and think about it.
‫Now let's see the challenge solution.
‫Let's go to the main activity.
‫And here I will use inside Build.gradle.
‫I will use.
‫Build features and data binding equal to true sync now.
‫Let's find the.
‫Late and shade var binding.
‫It's of the main activity.
‫I need to change it to layout and cut the layout tag from here.
‫Okay.
‫Main activity or activity.
‫Main activity.
‫Main binding.
‫Okay.
‫And binding.
‫Equal to binding util.
‫Binding util dot.
‫Alt+ enter to import to import it.
‫Dot.
‫Set content view to r dot layout dot activity main and I will pass the.
‫Activity.
‫This.
‫As the first component now.
‫I will create two functions.
‫One for displaying the hello text.
‫From the main thread and the second will display the hollow text from the background thread.
‫So binding dot text one dot.
‫Or I can start by like this.
‫I will call.
‫Say hello.
‫From main thread.
‫Function and say hello from back.
‫Threat.
‫I will create those two functions here.
‫Inside the main activity.
‫And create function.
‫I will start with the main thread.
‫So.
‫I will use the Coroutines.
‫Of course you can say hello directly from the main thread, but I will show you how to use coroutines
‫and how to use the dispatcher in order to detect what type of or where you can run your your coroutines
‫coroutine scope.
‫I passed dispatchers dispatchers dot main.
‫This is from the main dot launch and here I will say text or binding dot text one dot text.
‫Equal to.
‫Hello from and here I need to set thread name.
‫I will use thread dot current thread dot name the second.
‫Is the coroutine scope.dispatchers.io.
‫The background for input and output launch binding dot text to dot text equal to.
‫Hello.
‫From.
‫Thread dot.
‫Current thread dot name.
‫Okay, so here I am calling these two functions.
‫One uses the coroutine, which is the dispatcher's domain.
‫This is the context.
‫And here the context which is the dispatcher IO, which is the background thread.
‫Let me run the application and see.
‫And there we go.
‫Congratulations, guys.
‫I'm saying hello from the main and saying hello from default.
‫Dispatcher Worker number two.
‫So this is how we use the main thread using the coroutines and how to use the background thread in a
‫separate thread and separate Coroutine which is the i o.