android-architecture-components

Room query with dynamic values using placeholders

☆樱花仙子☆ 提交于 2019-12-11 14:56:23
问题 I am implementing a Room database (because I want to move away from Loaders) and I have a query that selects objects based on the IN operator: @Query(SELECT * FROM table WHERE icon IN(:icons)) LiveData<List<Result>> getResults(String[] icons); The issue is that the :icons array is generated dynamically during runtime, first I generate placeholders for it and then replace them with the values, like so: @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super

Relation on entities - android

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 10:19:08
问题 I am using from architect component and I need to set a lot of query on bellow values. How to create relation between bellow entities for query ? in normal mode I can't access to nested objects. For example I need to @Query("SELECT * FROM Content Where parent_id = 100") and other queries or I need to values that the name is JIM... but in normal mode I can't access to nested objects. @Entity(tableName = "tblCourseContentList") public class CourseContentListModel { @PrimaryKey(autoGenerate =

View not updating after first time triggering LiveData when using background job in Android

折月煮酒 提交于 2019-12-11 08:07:35
问题 I'm building a debt application in Android using Dagger 2, Room and MVVM. My problem lies with the reactivity of my main view, where a list of debts are shown and you can tick them off. When this activity is launched all the debts are loaded correctly, however when I insert a new debt the view is not updated accordingly . The strange part is that when I tick one of them off the view refreshes as expected. After much debugging I can infer that the problem has to do with the Lifecycle of the

Paging Library and Room with different PagedLists that depends of different requests

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 07:58:32
问题 I am trying to set up all my lists using new Android Architecture Components: Room Persistance Library and Paging Library. But I am facing the following problem. Imagine an app that has a lots of diferents lists of the same model. Each list has his own url request to server. Some elements can be repeated in diferent responses. So I think that I have to insert and update all elements of each response to a table of that model. Furthermore, each request has pages. For example, elements/famous/0

How can I make one ViewModel class return multiple data types to an activity or a fragment

拟墨画扇 提交于 2019-12-11 07:33:39
问题 I'm reading this blog post Using Android Architecture Components with Firebase Realtime Database (Part 2) and I'm implementing the last code snippet, and its working. private final FirebaseQueryLiveData liveData = new FirebaseQueryLiveData(HOT_STOCK_REF); private final MediatorLiveData<HotStock> hotStockLiveData = new MediatorLiveData<>(); public HotStockViewModel() { // Set up the MediatorLiveData to convert DataSnapshot objects into HotStock objects hotStockLiveData.addSource(liveData, new

Navigation Host becomes null while navigating (Android Navigation Component)

懵懂的女人 提交于 2019-12-11 05:43:08
问题 I am creating a game where the user goes through a series of 5 screens. At the last screen, the user has the choice to end the game, at which point they are taken back to the starting screen. My problems come in when a user ends the game and then starts again. While navigating through the app, the navigation host fragment cannot be found. The first time through the app, it navigates at usual, but the second time , the navigation host cannot be found. I have tried using different views to find

How can I navigate from an activity to another using Navigation Component and removing the first activity from the stack?

天涯浪子 提交于 2019-12-11 04:13:26
问题 In my app I have two activities (AuthenticationActivity and MainActivity), each one with a nav graph and a big flow of fragments. I've created an action to navigate from a fragment of the AuthenticationActivity's graph to the MainActivity but it does not remove the AuthenticationActivity from the stack even if I set 'popTo' to the Authentication graph id. 回答1: finish authentication activity after navigate method: button2.setOnClickListener { view.findNavController().navigate(R.id.action

How to clear/remove all items in page list adapter

耗尽温柔 提交于 2019-12-11 03:18:53
问题 I'm using the android paging library to show search result items, is there any way I can clear/remove all the loaded result items, Calling Invalidate on live Paged List refreshing the list not clear/remove items In Activity: fun clearSearchResult() { if (productSearchResultItemAdapter.itemCount > 0) { viewModel.invalidateResultList() } } In ViewModel private fun searchProductByTerm(searchTerm: String): Listing<Item> { sourceFactory = ProductSearchItemDataSourceFactory(productSearchUC,

Cannot create an instance of class - ViewModel

回眸只為那壹抹淺笑 提交于 2019-12-11 02:35:23
问题 I'm following an example of google, the example is in java but when I rewrite it in kotlin I can not instantiate the class. I am learning viewmodel. I have a lot of doubt if I messed up the syntax of my kotlin code. https://github.com/googlecodelabs/android-room-with-a-view class MainActivity: AppCompatActivity() { // private lateinit var mWordViewModel: WordViewModel //not works private var mWordViewModel: WordViewModel? = null //not works private var wordListAdapter: WordListAdapter?= null

TypeConverters not working for Collections in @Query

我只是一个虾纸丫 提交于 2019-12-11 02:28:24
问题 I've an entity called Events which is defined as follows: @Entity(tableName = "Events") data class Event(@PrimaryKey val id: Long, val name: String, val venues: Set<String>, val rating: Int) I've a pair of @TypeConverter methods for handling Set<String> : @TypeConverter fun fromStringToStringSet(str: String): Set<String> = str.split("<|>") @TypeConverter fun fromStringSetToString(set: Set<String>): String = set.joinToString("<|>") In my Dao , I've a method annotated with @Query as follows: