ViewModel in Android Application
- UI controller like activities / fragments primary intented to display data, react to user actions, or handling OS communication, etc.
- ViewModel will separate view data handling and UI controller logic
- ViewModel scope is available from Activity onCreate() to onDestroy()
- ViewModel won't loss data if our Activity destroys or re-created due to configuration changes by OS
******without ViewModel******
1) Create activity with TextView and Button
2) Declare counter variable in activity and display with TextView
3) on button click increment count and display updated value with textview
4) run and test the output by incrementing counter 4-5 times
- also change orientation of device then it will loss the value
******with ViewModel******
1) Create class by extending ViewModel class
2) declare MutableLiveData Integer counter instance
3) create getter and setter method for counter instance
def lifecycle_version = "2.3.1"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
4) create instance of ViewModel inside Activity as below
MyViewModel model = new ViewModelProvider(this).get(MyViewModel.class);
5) call counter getter method and also implement observe method with livedata and set value with textview
6) run the app and check the output by changing orientation
--if you any query then you can comment on comment box.
#viewmodel #android #coding #example
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «ViewModel in Android Application», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.