android-livedata

Restoring Room database from a local backup file, LiveData ViewModel doesn't refresh

限于喜欢 提交于 2021-01-28 00:20:35
问题 I'm trying to restore a room database programmatically. I followed this tutorial to implement a view model using LiveData of Words list, so that the words list refresh automatically on screan when insert, delete or update. mWordViewModel.getAllWords().observe(this, new Observer<List<Word>>() { @Override public void onChanged(@Nullable final List<Word> Words) { // Update the cached copy of the Ussds in the adapter. adapter.setWords(Words); } }); I also used the following code to backup and

Android viewModel savedStateHandle

落爺英雄遲暮 提交于 2021-01-27 21:09:27
问题 This is more of a conceptual question. Android recently introduced the concept of handling the state during process death inside viewModel rather than savedInstanceState which previously used to be in Activity or Fragment. My question is how do I test this process death? If I rightly understand the documentation, the Process death happens to be Android killing the app due to full memory when app is no longer used in background. Also will the viewModel save the state when user kills the app

how to use viewmodel singleton for activities?

故事扮演 提交于 2021-01-27 07:30:42
问题 MyApp need hold a User object in whole context,A,B,C activities'xml use this User object,when A edit User,I want B and C notifyChange,how to deal this problem with databinding,livedata and viewModel? Formerly I make User.class extend BaseObservable,but POJO will be very troublesome and must not be a null,sometimes User maybe null such as not login. Now I Change to use LiveData, make Pojo simple and not extend BaseObservable,but when A edit,B and C not work,I think i need ABC use same

how to use viewmodel singleton for activities?

白昼怎懂夜的黑 提交于 2021-01-27 07:30:22
问题 MyApp need hold a User object in whole context,A,B,C activities'xml use this User object,when A edit User,I want B and C notifyChange,how to deal this problem with databinding,livedata and viewModel? Formerly I make User.class extend BaseObservable,but POJO will be very troublesome and must not be a null,sometimes User maybe null such as not login. Now I Change to use LiveData, make Pojo simple and not extend BaseObservable,but when A edit,B and C not work,I think i need ABC use same

How and where to use Transformations.switchMap?

梦想与她 提交于 2021-01-20 14:12:18
问题 In recent Android Architecture Components library released by Google, we have two static functions in the Transformations class. While the map function is straight forward and easily understandable, I am finding it hard to properly understand the switchMap function. The official documentation of switchMap can be found here. Can somebody explain how and where to use the switchMap function with a practical example? 回答1: In the map() function LiveData userLiveData = ...; LiveData userName =

How and where to use Transformations.switchMap?

十年热恋 提交于 2021-01-20 14:11:11
问题 In recent Android Architecture Components library released by Google, we have two static functions in the Transformations class. While the map function is straight forward and easily understandable, I am finding it hard to properly understand the switchMap function. The official documentation of switchMap can be found here. Can somebody explain how and where to use the switchMap function with a practical example? 回答1: In the map() function LiveData userLiveData = ...; LiveData userName =

onResume does not worked in viewmodel

房东的猫 提交于 2021-01-20 13:11:20
问题 my data is fetched only when it is created...im using viewmodel...when press back button it doesnt update the previous data..onresume is not working in this... i refered this but none of those helped--> Reacting to activity lifecycle in ViewModel i need help thanks in advance activity:-- class MyAccount : BaseClassActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.myaccount) var mActionBarToolbar = findViewById<androidx

onResume does not worked in viewmodel

半城伤御伤魂 提交于 2021-01-20 13:09:42
问题 my data is fetched only when it is created...im using viewmodel...when press back button it doesnt update the previous data..onresume is not working in this... i refered this but none of those helped--> Reacting to activity lifecycle in ViewModel i need help thanks in advance activity:-- class MyAccount : BaseClassActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.myaccount) var mActionBarToolbar = findViewById<androidx

Updating a RecyclerView by a new LiveData<List> return from Room dynamically

試著忘記壹切 提交于 2021-01-07 06:11:57
问题 I have a conventional Room->DAO->Livedata->Repositiry->ViewModel->RecyclerView app. Different buttons of UI must pass different lists of data to RecyclerView. By button click I want: Make new @Query in DAO and get new LiveData<`List> object in return. Put this new data into the RecyclerViewAdapter and call notifyDataSetChanged () to make new List visuals. The Dao @Query: @Query("SELECT * FROM entry_table WHERE path LIKE :path ORDER BY priority DESC") LiveData<List<Entry>> getNotesOfFolder

Updating a RecyclerView by a new LiveData<List> return from Room dynamically

偶尔善良 提交于 2021-01-07 06:11:27
问题 I have a conventional Room->DAO->Livedata->Repositiry->ViewModel->RecyclerView app. Different buttons of UI must pass different lists of data to RecyclerView. By button click I want: Make new @Query in DAO and get new LiveData<`List> object in return. Put this new data into the RecyclerViewAdapter and call notifyDataSetChanged () to make new List visuals. The Dao @Query: @Query("SELECT * FROM entry_table WHERE path LIKE :path ORDER BY priority DESC") LiveData<List<Entry>> getNotesOfFolder