android-architecture-components

Android Jetpack Navigation How to handle the Toolbar and BottomNavBar content

陌路散爱 提交于 2021-02-07 11:21:49
问题 I am a bit confused on how the Navigation component fits in the app behavior. It all looks nice and shiny in tutorials where you don't do things too complex but when implementing in real app, things seem different. Before Navigation Before implementing navigation I had to manually run fragment transactions. In order to do this, my fragment would implement an interface onFragmentAction which passed a bundle to the main Activity and in the activity based on the actions, replace the current

RecyclerView shows nothing when navigating back (navigation component)

人盡茶涼 提交于 2021-02-07 04:39:10
问题 I'm using navigation component with bottom navigation view in my app. Problem was when I return back to top-level destinations from child destination, recyclerView not showing any elements. nav_graph_main: <?xml version="1.0" encoding="utf-8"?> <navigation xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/nav_graph_main" app:startDestination="@id/navigation_stats">

LiveData not updating when data changes

断了今生、忘了曾经 提交于 2021-02-06 11:51:30
问题 I'm using LiveData to fetch data from a server and observe it. My onChanged() method just gets called the first time, and does not get called when data in the server gets updated. UserFragment: UserViewModel userViewModel = ViewModelProviders.of(this).get(UserViewModel.class); userViewModel.getUser().observe(this, new Observer<User>() { @Override public void onChanged(User user) { //Set UI } }); UserViewModel: public class UserViewModel extends AndroidViewModel { private LiveData<User> user;

Android Navigation library deep linking: How to synthesise backstack

南楼画角 提交于 2021-02-06 08:51:47
问题 Using Android Architecture's Navigation component, I have the following navigation graph -> [Home] -> [Articles List] -> [Specific Article] I also have a deeplink to [Specific Article] . When it is opened, navigating up currently goes to [Home] . I'd like to synthesise a backstack such that navigating up instead goes back to [Articles List] (and then on to [Home] if navigating again). What is the Navigation way of doing this? 回答1: Per the NavDeepLinkBuilder documentation, Navigation uses the

Android Navigation library deep linking: How to synthesise backstack

强颜欢笑 提交于 2021-02-06 08:49:35
问题 Using Android Architecture's Navigation component, I have the following navigation graph -> [Home] -> [Articles List] -> [Specific Article] I also have a deeplink to [Specific Article] . When it is opened, navigating up currently goes to [Home] . I'd like to synthesise a backstack such that navigating up instead goes back to [Articles List] (and then on to [Home] if navigating again). What is the Navigation way of doing this? 回答1: Per the NavDeepLinkBuilder documentation, Navigation uses the

Nested Observers with LiveData (Observing an observer)

北战南征 提交于 2021-01-29 05:18:05
问题 I have a case where I have BottomNavigationView where fragments are shown/hidden instead of adding/replacing, therefore they do not go through their lifecycle every time. Fragment 1 is observing one database table, Fragment 2 is observing a different one. My goal is to call the onChanged of Fragment 2 when onChanged of Fragment 1 is called. A stupid and naive solution that worked was to set up the observer of Fragment 1 in Fragment 2 and inside it call another observer: mFragment1ViewModel1

How to share view models between fragments using Google's GithubBrowserSample approach?

a 夏天 提交于 2021-01-27 12:08:01
问题 I am very new using Android architecture components, so I decided to base my application using GithubBrowserSample to achieve many of my use cases. But i have the problem that i don´t know what is the correct way to share viewmodels between fragments with this approach. I want to share the view model because i have a fragment with a viewpager with 2 fragments that need to observe data of the parent fragment view model I used this before to achieve it, based on google's documentation override

AppWidgetProvider with Android Architecture Component

做~自己de王妃 提交于 2021-01-27 07:36:35
问题 I want to implement Android Architecture Component with AppWidgetProvider. I'm not sure to map properly Widget LifeCycle to LifeCycle events. I created a BaseAppWidgetProvider to be extented by my widgets: /** * Base class for {@link BaseAppWidgetProvider} to manage {@link Lifecycle} */ public abstract class BaseAppWidgetProvider extends AppWidgetProvider implements LifecycleOwner { private final AppWidgetProviderLifecycleDispatcher mDispatcher = new AppWidgetProviderLifecycleDispatcher(this)

AppWidgetProvider with Android Architecture Component

我们两清 提交于 2021-01-27 07:36:31
问题 I want to implement Android Architecture Component with AppWidgetProvider. I'm not sure to map properly Widget LifeCycle to LifeCycle events. I created a BaseAppWidgetProvider to be extented by my widgets: /** * Base class for {@link BaseAppWidgetProvider} to manage {@link Lifecycle} */ public abstract class BaseAppWidgetProvider extends AppWidgetProvider implements LifecycleOwner { private final AppWidgetProviderLifecycleDispatcher mDispatcher = new AppWidgetProviderLifecycleDispatcher(this)

pagedList loading all items at once

情到浓时终转凉″ 提交于 2021-01-27 05:40:34
问题 I've trying to integrate the architecture components in my app, viz Pagination, LiveData, ViewModel. Room is already integrated and tested before so I can return a DataSource.Factory<Integer, DbEntity> from my DAO class. This is my code for creating LiveData of PagedList: PagedList.Config pagedListConfig = (new PagedList.Config.Builder()).setEnablePlaceholders(true) .setPrefetchDistance(5) .setPageSize(10) .setInitialLoadSizeHint(10) .build(); LiveData<PagedList<DbEntity>> dbEntities = new