android-livedata

Room does not insert data to table

自闭症网瘾萝莉.ら 提交于 2019-12-13 16:11:18
问题 It is interesting point that it sometimes performs insert operation correctly. I do not know why and how this situation can be happens. So, I could not figure out where I made a mistake(s). Here is my project files. 1) SentFilesDao.java @Dao public interface SentFilesDao { @Query("SELECT id, name, type, status, dateTime FROM sent") LiveData<List<SentFilesEntity>> getAllSentFiles(); @Insert(onConflict = OnConflictStrategy.IGNORE) void insert(SentFilesEntity file); @Query("DELETE FROM sent")

Observing viewmodel for the second time returns null in android

≯℡__Kan透↙ 提交于 2019-12-13 13:06:57
问题 In my android app,im following architecture components with mvvm pattern. my app makes a network call to display the weather information.api call is being made from repository which returns a livedata of response to the viewmodel,which inturn is observed by my main activity. the app works fine except for one condition,whenever i disconnect the internet to test the fail case,it inflates error view as required in the error view i have a retry button,which makes the method call to observe the

Android ViewModel: Should I “borrow” the observe() method from LiveData like in the official example?

孤人 提交于 2019-12-13 10:29:26
问题 When working with ViewModels the View observes the ViewModel. It has to register as an observer. In the official tutorial of Google this registration is delegated to the observe() method of a LiveData object. public class MyViewModel extends ViewModel { private MutableLiveData<List<User>> users; public LiveData<List<User>> getUsers() { if (users == null) { users = new MutableLiveData<List<Users>>(); loadUsers(); } return users; } private void loadUsers() { // Do an asynchronous operation to

Initializing Firebase in Modulair Android project written in kotlin gives not initialized error

为君一笑 提交于 2019-12-13 06:14:51
问题 I'm having difficulty trying to implement firebase into an modulair android project written in kotlin. My structure looks like this: App Feature Base And then in my main activity oncreate I'm calling the FirebaseApp.inialize(this) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) FirebaseApp.initializeApp(this) setContentView(R.layout.activity_main) spotifyAuthDataViewModel = ViewModelProviders.of(this) .get(SpotifyAuthDataViewModel::class.java) val

Update Object type LiveData with Databinding

…衆ロ難τιáo~ 提交于 2019-12-13 03:39:50
问题 I want to update views via databinding with livedata. Lets have a look at the scenario. Data Class data class Movie(var name: String = "", var createdAt: String = "") ViewModel class MyViewModel: ViewModel(){ var pageTitle: MutableLiveData<String>() var movie: MutableLiveData<Movie>() fun changeTitleAndMovieName() pageTitle.value = "Title Changed" movie.value.name = "Movie Name Changed" } } XML <layout> ... <TextView ... android:text="@{`Title: `+viewmodel.pageTitle `Name: `+viewmodel.movie

How to convert LiveData<List<Foo>> into LiveData<List<Bar>>?

我只是一个虾纸丫 提交于 2019-12-12 13:39:44
问题 Let's say we have two objects of LiveData: LiveData<List<Foo>> fooList; LiveData<List<Bar>> barList; And by some method (or the constructor) Foo can be converted to the Bar object. What is the best way to convert the first observable, which has the list of Foo objects to the observable with the list of Bar objects. I know that it is possible to do this: barList = Transformations.map(fooList, fooList1 -> { List<Bar> barList = new ArrayList<>(); for (Foo foo: fooList1) { barList.add(new Bar(foo

Multiple LiveData Observers After Popping Fragment

旧城冷巷雨未停 提交于 2019-12-12 10:35:38
问题 Issue Summary : Multiple LiveData Observers are being triggered in a Fragment after navigating to a new Fragment, popping the new Fragment, and returning to the original Fragment. Details : The architecture consists of MainActivity that hosts a HomeFragment as the start destination in the MainActivity's navigation graph . Within HomeFragment is a programmatically inflated PriceGraphFragment . The HomeFragment is using the navigation component to launch a new child Fragment ProfileFragment .

LiveData List doesn't update when updating database

a 夏天 提交于 2019-12-12 10:05:58
问题 I'm currently refactoring legacy code to use Android Architecture Components and set up a room db and volley requests within a kind of repository pattern. So the presentation/domain layer asks the repository to get LiveData-Objects to observe or tell him to synchronize with the server, after which old db entries are deleted and all current ones refetched from the server. I've written tests for the synchronization part, so I'm sure, that the objects get fetched and inserted to the database

Real Time Data from Sqlite database through Room outside Activity/Fragment following MVVM Model

橙三吉。 提交于 2019-12-11 22:15:08
问题 I am following the MVVM Model. I would like to have Real-time data from SQLite database through Room (Results shall available as soon as data changes in Database). With LiveData, we can get results in Activity/Fragment. Callback also won't good on this type of requirement since data should be pushed from the database. Is there any way I can get in any class outside of activity/fragment?. Thanx in advance for your help. EDIT Putting sample code for better understanding..Is there a way to

Room not returning duplicates

北战南征 提交于 2019-12-11 19:35:35
问题 So I have a room database all set up, everything is fine, so I can make queries and inserts, delete etc no problems, however i've just run into a situation where id like to return entries by their Ids and duplicates should be allowed, however room is removing the duplicates, so for instance I send it a list of ids say <1,2,3,2,3> and it returns items by their ids but only sends me <1,2,3> removing the duplicate entries. The query I'm making is below (btw complete noob at sql) @Query("SELECT *