android-architecture-components

How to change label attribute of a destination in navigation controller?

陌路散爱 提交于 2019-12-24 04:28:12
问题 I am trying to use navigation controller in Android as you can see in the image above, I set the label attribute of my destination to be 'Home'. and this label, will show like title in my toolbar. can I change that label programatically ? because I want to set my toolbar title dynamically. I have tried to change the toolbar title using toolbar.title = "some title here" but it will always be overlapped the title from that label. so how to solve this ? 回答1: Do it in your activity like below it

Usage of executor in android architecture components

拟墨画扇 提交于 2019-12-24 01:48:07
问题 public class UserRepository { private final Webservice webservice; private final UserDao userDao; private final Executor executor; @Inject public UserRepository(Webservice webservice, UserDao userDao, Executor executor) { this.webservice = webservice; this.userDao = userDao; this.executor = executor; } public LiveData<User> getUser(String userId) { refreshUser(userId); // Returns a LiveData object directly from the database. return userDao.load(userId); } private void refreshUser(final String

Error: Cannot find ActivitySplashBinding

耗尽温柔 提交于 2019-12-23 22:46:55
问题 I am trying to check that if user is logged on or not. If yes then show a specific view group otherwise show different view group. To check whether user is logged on or not I am fetching the user from shared preference (at the time of login user is saved in shared preference). Let me show my code. SplashViewModel public class SplashViewModel extends ViewModel { public final String TAG = "SplashViewModel"; private final String GREETING = "Hi "; public ObservableBoolean isLoggedIn = new

Room database architecture entity extends error

风流意气都作罢 提交于 2019-12-23 22:06:00
问题 While using android Room i'm having the following entity: @Entity public class Call implements Parcelable { @PrimaryKey(autoGenerate = true) private long id; private String filePath; private long durationInMillis; private String phoneNumber; private int isStarred; private int isIncoming; private long timestampCreated; } All works great. But now I want my pojo (Call.class) to extends an Abstract class as following: @Entity public class Call extends BaseViewTypeData implements Parcelable { ....

Navigation architecture: How to manage proper navigation without using clearTask as it is deprecated

梦想与她 提交于 2019-12-23 18:53:21
问题 While using navigation architecture as from here , here clearTask is deprecated. My scenario is this: There are 2 screens Login and Registration, both have links to each other. So you can go to Registration from Login and also Login from Registration. But on back Press App should be closed. It could simply be done by just adding clearTask to both actions as below. <?xml version="1.0" encoding="utf-8"?> <navigation xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http:/

Android Live data observer exception

。_饼干妹妹 提交于 2019-12-23 18:52:49
问题 I am trying to implement the new android architecture components and have used live data in the fragment and view model but when I add an observer to the live data the app crashes throwing this exception. Process: com.nrs.nsnik.architecturecomponents, PID: 3071 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nrs.nsnik.architecturecomponents/com.nrs.nsnik.architecturec omponents.view.MainActivity}: java.lang.ClassCastException: android.arch.lifecycle.LiveData

room crashes while accessing it store data

扶醉桌前 提交于 2019-12-23 13:24:15
问题 I using work manager to save data to my local database and then put the same data to the server. In localDeleteRequest class, I am passing id as WorkData and using that id to get the object which is being stored in the local database Work Manager function: private fun deleteUserWork(userEntity: UserEntity) { val workManager: WorkManager = WorkManager.getInstance() val constraint = Constraints.Builder() .setRequiredNetworkType(NetworkType.CONNECTED) .build() val inputData: Data = mapOf("id" to

EditText LiveData Two-way binding

女生的网名这么多〃 提交于 2019-12-23 09:26:59
问题 Okay, so I have a ViewModel with a getter getTitle() that returns MutableLiveData<String> . <EditText style="@style/Widget.EditText.FullWidth" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/label_title" android:inputType="text" android:text="@={ viewModel.title }" /> This works fine at first: the EditText contains the value of the MutableLiveData when it first appears. However, if the value of this data is updated using MutableLiveData.setValue(

Why is the value param nullable in Observer from Android Architecture Components?

时光毁灭记忆、已成空白 提交于 2019-12-23 07:46:10
问题 LiveData from architecture components defines an Observer with nullable value for the receiver callback: public interface Observer<T> { /** * Called when the data is changed. * @param t The new data */ void onChanged(@Nullable T t); } Why is there an explicitly nullable annotation? The doc of LiveData.observe() also says: If LiveData already has data set, it will be delivered to the observer. E.g. Observer waits for non-nullable updates or immediately receive previous non-nullable value, that

Android Architecture Component ViewModel - How to mock ViewModel on test Activity?

删除回忆录丶 提交于 2019-12-23 07:42:26
问题 I'm trying to setup UI testing similar to GithubBrowserSample and it looks like the sample project only has mock ViewModel for Fragment but not an example for Activity . Here's my code where I am trying to test the Activity by mocking ViewModel . But the ViewModel is not getting set before onCreate() in Activity. @RunWith(AndroidJUnit4::class) class MainActivityTest { val viewModel = mock(MainViewModel::class.java) @Rule @JvmField val activityRule = ActivityTestRule<MainActivity>(MainActivity