android-architecture-components

<androidx.fragment.app.FragmentContainerView> vs <fragment> as a view for a NavHost

痴心易碎 提交于 2019-12-12 18:41:14
问题 When using androidx.fragment.app.FragmentContainerView as a navHost instead of a regular fragment app is not able to navigate to a destination after orientation change. I get a following error: java.lang.IllegalStateException: no current navigation node Is there a gotcha that I should know about to use it properly or is my way of using nav components is incorrect? Simple activity xml with a view: ... <androidx.fragment.app.FragmentContainerView android:id="@+id/nav_host_fragment" android:name

Android instrumentation test doesn't run to end when using Room @Transaction function

匆匆过客 提交于 2019-12-12 18:04:28
问题 I'm testing with AS 3.4.1 and Emulator running Android 9. The following test won't run, when I use a Room Dao Function annotated with @Transaction in it. class RecurrenceManagerTest : DatabaseTest() { @Rule @JvmField val instantTaskExecutorRule = InstantTaskExecutorRule() var recurringEntryId: Long = -1 @Before override fun setup() { super.setup() // only initialized the db val recurringEntry = RecurringEntry( recurrence = Recurrence(DATE.toEpochMilli(), Recurrence.DAILY) ) recurringEntryId =

Android Rooms - Search in String

大兔子大兔子 提交于 2019-12-12 15:42:34
问题 In Android Rooms persistence library, how would I write the following SQL statement: SELECT * FROM table WHERE field LIKE %:value% As a @Query? This syntax is invalid, and I can't find anything about it in the docs. 回答1: You can just concat using SQLite string concatenation. @Query("SELECT * FROM table WHERE field LIKE '%' || :value || '%'") 回答2: Annswer by @yigit works great for me: @Query("SELECT * FROM stores " + "WHERE name LIKE '%' || :search || '%' " + "OR description LIKE '%' ||

Get Backstack status using android navigation component

橙三吉。 提交于 2019-12-12 10:36:42
问题 I want to implement backpress behaviour such that it prompts a confirmation popup when you press back with the backstack empty, otherwise it pops the next fragment in the stack. I'm trying to get the backstack count, but i always get 0 from both fragment managers getSupportFragmentManager().getBackStackEntryCount(); getFragmentManager().getBackStackEntryCount(); I guess it should work since i checked the google code of fragment navigator and it adds to backstack through the canonical fragment

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

Ignoring navigate() call: FragmentManager has already saved its state

為{幸葍}努か 提交于 2019-12-12 09:38:25
问题 I'm using navigation in MainActivity , then I start SecondActivity (for result). After finish of SecondActivity I would like to continue with navigation in MainActivity , but FragmentManager has saved his state already. On Navigation.findNavController(view).navigate(R.id.action_next, bundle) I receive log message: Ignoring navigate() call: FragmentManager has already saved its state How I can continue in navigation? 回答1: You must always call super.onActivityResult() in your Activity's

How to set target fragment of a dialog when using navigation components

大兔子大兔子 提交于 2019-12-12 08:31:17
问题 I'm showing a dialog inside a fragment using childFragmentManager or within an Activity using the supportFragmentManager , in the process I would like to set the target fragment, like this: val textSearchDialog = TextSearchDialogFragment.newInstance() textSearchDialog.setTargetFragment(PlaceSearchFragment@this, 0) But when running that code I get the error: java.lang.IllegalStateException: Fragment TextSearchDialogFragment{b7fce67 #0 0} declared target fragment PlaceSearchFragment{f87414 #0

How do I create a PagedList of an object for tests?

戏子无情 提交于 2019-12-12 07:47:40
问题 I have been working with the arch libraries from Google, but one thing that has made testing difficult is working with PagedList . For this example, I am using the repository pattern and returning details from either an API or network. So within the ViewModel I make a call to this interface method: override fun getFoos(): Observable<PagedList<Foo>> The Repository will then use RxPagedListBuilder to create the Observable that is of type PagedList: override fun getFoos(): Observable<PagedList

Can't resolve the Context or Application while navigating from Adapter of a fragment(A) to another Fragment (B)

拈花ヽ惹草 提交于 2019-12-11 19:35:18
问题 Am trying to navigate from one fragment (A) to another (B), but the fragment, but the first fragment (A) has a recyclerView meaning when I click on any Item I should navigate to the next one. Am using android Navigation component but I couldn't resolve the method findNavController(xxx) since it requires the ApplicationContext of the fragment. , because I tried v.getContext() , v.getApplicationContext() , mContext , but there wasn't luck. How can I resolve this issue, below is the

How to navigate to Half Fragment ? (Navigation Architecture Component)

六月ゝ 毕业季﹏ 提交于 2019-12-11 17:39:58
问题 I am trying Navigation architecture Component in My app. Earlier i Used Fragment Transaction's to achieve the below feature. Basically i want to navigate from. FragmentA->FragmentB (custom fragment partially transparent and half of screen size) If i am using Navigation component and try Navigation.findNavController(view).navigate(R.id.action_FragmentA_to_FragmentB) Then the result is the FragmentA is replaced by FragmentB and the background fragment is not visible. I want to know of a