Android : ViewModelStore
Explore how ViewModelStore works in Android Development!

Senior Android Engineer from Bangladesh. Love to contribute in Open-Source. Indie Music Producer.
Search for a command to run...
Explore how ViewModelStore works in Android Development!

Senior Android Engineer from Bangladesh. Love to contribute in Open-Source. Indie Music Producer.
No comments yet. Be the first to comment.
In this series, I will write about Android App Development.
Securely managing WebView Callbacks for Payments, Orders, and Others with BuildConfig in Android.
A practical guide to choosing the right coroutine primitive for your Android/Kotlin projects

This guide explains what Channels are, when to use them, how to use them correctly, and when NOT to use them β in simple, professional language. 1. What problem do Channels solve? In Kotlin coroutines, you often have multiple coroutines running at t...

Learn how to build preview-safe ViewModels in Jetpack Compose using Hilt.

HandlerInterceptor vs Filter in Spring Boot: A Practical Guide with JNDI Injection Prevention

Simple In-Memory Caching: A Tiny Trick with Massive Impact

Ever wondered how ViewModel survive during configuration changes in our Android apps? π€
Let me introduce you to ViewModelStore!
ViewModelStore?ViewModelStore is a class that stores and manages ViewModel instances. It's essential for keeping our ViewModels alive during configuration changes like screen rotations.
RetainViewModels: Keeps ViewModels during configuration changes.
Efficient Resource Management: Automatically clears and notifies ViewModels when they are no longer needed, preventing memory leaks.
Easy Access: Retrieve ViewModelStore instances using ViewModelStoreOwner.getViewModelStore.
Storing ViewModels: Use the put method to add a ViewModel with a unique key. If a ViewModel with the same key exists, it's replaced and the old one is cleared.
Retrieving ViewModels: Use the get method to fetch a ViewModel by its key.
Listing Keys: Use the keys method to get a set of all keys.
Clearing ViewModels: Call the clear method to notify and remove all ViewModels.

Implementing ViewModel in our app can significantly enhance its stability and performance. Give it a try and see the difference!
That's it for today. Happy Coding...