android-architecture-components

How to add listener to android Navigation Architecture Component action animation

╄→гoц情女王★ 提交于 2020-01-24 20:29:27
问题 I want to execute some code by the end of an animation that I've set to an action, is there some way to add a listener to navigation controller action animation? 来源: https://stackoverflow.com/questions/55341088/how-to-add-listener-to-android-navigation-architecture-component-action-animatio

The correct way to obtain a ViewModel instance outside of an Activity or a Fragment

这一生的挚爱 提交于 2020-01-22 19:26:21
问题 I'm building a location app where I display background locations from a Room database in my MainActivity. I can get a ViewModel by calling locationViewModel = ViewModelProviders.of(this).get(LocationViewModel.class); locationViewModel.getLocations().observe(this, this); Periodic background locations should be saved to the Room database when I receive location updates via a BroadCastReceiver. They should be saved by calling locationViewModel.getLocations().setValue() public class

The correct way to obtain a ViewModel instance outside of an Activity or a Fragment

折月煮酒 提交于 2020-01-22 19:26:02
问题 I'm building a location app where I display background locations from a Room database in my MainActivity. I can get a ViewModel by calling locationViewModel = ViewModelProviders.of(this).get(LocationViewModel.class); locationViewModel.getLocations().observe(this, this); Periodic background locations should be saved to the Room database when I receive location updates via a BroadCastReceiver. They should be saved by calling locationViewModel.getLocations().setValue() public class

How to query nested Embeded objects using Room Persistance Library in android?

时光怂恿深爱的人放手 提交于 2020-01-22 18:21:43
问题 Consider I have 3 classes User, Address, Location class Address { public String street; public String state; public String city; @ColumnInfo(name = "post_code") public int postCode; @Embedded(prefix = "home_") public Location homeLocation; @Embedded(prefix = "office_") public Location officeLocation; } class Location{ public long lat; public long lng; } @Entity class User { @PrimaryKey public int id; public String firstName; @Embedded(prefix = "addr_") public Address address; } How should i

New navigation component from arch with nested navigation graph

感情迁移 提交于 2020-01-22 04:14:27
问题 I have one case and wish to implement it by arch navigation component. For example I have 2 Nav Graphs (main and nested). Can I call main graph from nested and how? example 回答1: The point is to get the right NavController to navigate in the right graph. Let's take this scenario as an example: MainActivity |- MainNavHost |- NavBarFragment | |- NestedNavHost | | |-NestedContentFragment1 | | |-NestedContentFragment2 | | | |- BottomNavigationView | |- LoginFragment The main graph and the nested

Paging library returns empty list initially

﹥>﹥吖頭↗ 提交于 2020-01-21 04:05:29
问题 I'm using Paging library to paginate a list of items I'm retrieving from my server. Initially, when my fragment is loaded, it returns an empty list. But after changing fragments and going back to that fragment, I can see the list loaded. After debugging I saw that data was actually being fetched, but an empty list was passed to my fragment. ItemDataSource: @Override public void loadInitial(@NonNull LoadInitialParams<Integer> params, @NonNull LoadInitialCallback<Integer, Item> callback) {

how to remove default animation transition when using navigation component in Android?

安稳与你 提交于 2020-01-15 09:14:36
问题 I am using Navigation component, and I have a bottom navigation view in the main activity. when I tap the tab in that bottom navigation view, it seems that there is a fade in animation when the fragment appear. I don't think I manually set the animation, it seems that the animation will be there by default. I want to remove that animation. here is the code I use in my Main Activity. class MainActivity : AppCompatActivity(), NavController.OnDestinationChangedListener { private lateinit var

how to remove default animation transition when using navigation component in Android?

孤街醉人 提交于 2020-01-15 09:14:33
问题 I am using Navigation component, and I have a bottom navigation view in the main activity. when I tap the tab in that bottom navigation view, it seems that there is a fade in animation when the fragment appear. I don't think I manually set the animation, it seems that the animation will be there by default. I want to remove that animation. here is the code I use in my Main Activity. class MainActivity : AppCompatActivity(), NavController.OnDestinationChangedListener { private lateinit var

Android Studio does't check/highlight Kotlin Room DAO queries when string occupies more than 1 row

让人想犯罪 __ 提交于 2020-01-14 10:27:08
问题 When I'm trying to break query for better readability/comprehension it stops being checked by IDE. This occurs on Android Studio 3.2 canary 16 and 3.1.2 stable, kotlin version 1.2.41. When Room DAO is java class/interface everything works fine. Is it possible to have the same checking/highlighting for 2+ rows queries in kotlin as in java? 回答1: This is supposed to be resolved in AS 3.6, but, for now, the workaround noted at https://issuetracker.google.com/issues/130141151#comment3 does the

Android ViewModel LiveData update view on button click

自作多情 提交于 2020-01-13 19:21:34
问题 I am following this tutorial to learn ViewModel and LiveData. In my case, instead of getting data from network, I am simply generating random string on button click and trying to update a textview. The problem is that the textview does not get updated when the data is changed by button click, but only gets updated when orientation is toggled. Activity Class (extends LifecycleActivity) public class PScreen extends BaseActivity { @Override protected void onCreate(@Nullable Bundle