Send Data From Activity to Fragment using ViewModel Kotlin Android Studio

79 Просмотры
Издатель
In this video we are going to implement the thing to send data from an activity to fragment and fragment to fragment using View Model.

To reuse fragments, build each as a completely self-contained component that defines its own layout and behavior. Once you have defined these reusable fragments, you can associate them with an activity and connect them with the application logic to realize the overall composite UI.

To properly react to user events, or to share state information, you often need to have channels of communication between an activity and its fragments or between two or more fragments. To keep fragments self-contained, you should not have fragments communicate directly with other fragments or with its host activity.

The Fragment library provides two options for communication: a shared ViewModel and the Fragment Result API. The recommended option depends on the use case. To share persistent data with any custom APIs, you should use a ViewModel. For a one-time result with data that can be placed in a Bundle, you should use the Fragment Result API.

The following sections show you how to use ViewModel and the Fragment Result API to communicate between your fragments and activities.

Share data using a ViewModel
ViewModel is an ideal choice when you need to share data between multiple fragments or between fragments and their host activity. ViewModel objects store and manage UI data. For more information on ViewModel, see ViewModel overview.

Share data with the host activity
In some cases, you might need to share data between fragments and their host activity. For example, you may want to toggle a global UI component
based on an interaction within a fragment.
#sharedata #fragments #androidstudio
#viewmodel #sharedviewmodel #datasendfromactivitytofragment
#kotlin #kotlinvocabulary #kotlin101 #kotlincoroutinestutorial #kotlinevent21 #kotlintips #kotlin2021 #appdevelopment #appdeveloping2021 #appdeveloping #appdevelop #appdeveloper #coroutines #programming #coding #computerscience #programmingmemes ##recyclerview #linearlayout #relativelayout
#programming #programmer #developer #koder #AndroidDev #100DaysOfCode #Compose #Zoomable #Image #Rotation #Graphics #PointerInput #Scale #Room #RoomDatabase #Remember #MutableState #MutableList #LiveData #StateFlow #ListOf #EmptyList #RememberCoroutineScope #CoroutineScope #Scaffold #ScrollView #NestedScrollView #NestedScrollViewConnection #Surface #Modifier #MaterialTheme #BottomBar #RememberNavController #BottomNavigationItem #NavHostController #NavController #Room #RoomDatabase #OneToOneRelationship #Dao #Entity #ColumnInfo #Relation #Embedded #PrimaryKey #ForeignKey #Insert #Delete #Update #Create #Data #Volatile #Instance #Version #ViewModel #Repository #View #Model #MVVM #MutlipleTable #Table #Database #Composable #Compose #Row #Column #Kotlin #MAroidDev #Navigation #Developer #Programmer #AndroidSDK #Java #XML #JetpackComponent #RecyclerView #LazyColumn #LazyVerticalGrid #F#coder #coders #codered #coderlife #blocoderua #vocoder #coderslife #codergirl #coderpower #medicodermatologista #coderedlifestyle #brincoderesina #coderedbrand #pycoders #codere #coderdojo #coderood #medicalcoder #coderealize #decoder #encoder #cocoderoda #girlcoder #eatsleepcoderepeat #loldecoder #drumcoderecords#chuviscoderisco #viscoderm #coderworlds #coderlifestyle #sacoderisadas #valcodera #codereddvd #unpocoderelax #jalecoderenda #coderboy #dresscodered #coderedrebel
Категория
Язык программирования Kotlin
Комментариев нет.