In this video, I am going to talk to you about the challenge of using async await in activities, why it is an issue, and how to overcome it with the help of the ViewModel.
🍔 Takeaways
Async await doesn't know about activity lifetime events;
ViewModel is usually observable, out living activities and a fit for asynchronous operations;
INotifyPropertyChanged interface makes a class observable;
For more videos like this:
💡Subscribe: https://www.youtube.com/c/CodewithSaa....
🧩 Resources
Android Developer Guide: https://developer.android.com/guide
📺 Demo code:
Demo code: https://github.com/xiaomi7732/LearnAs...
CodeNameK related code: https://github.com/xiaomi7732/CodeWit...
💬 Discord server for Code w/ Saar: / discord
➡️ Reach me on twitter @CodeWithSaar. My home page: https://www.codewithsaar.net
☕ If you want to buy me a coffee: https://www.buymeacoffee.com/codewith... and thank you!
🔖 Chapters
00:00 Project preparation
02:11 Prepare layout
03:45 Start to repro issue for async await in activity
05:20 Analysis what was wrong
06:42 Seeking for potential solution
10:34 Implement a ViewModel class
11:57 Make view model observable by implementing interface of INotifyPropertyChanged
13:32 Create and a view model properly using ViewModelProvider