android-jetpack

Android P visibilityawareimagebutton.setVisibility can only be called from the same library group

不羁岁月 提交于 2019-12-08 22:46:15
问题 I'm trying to use the new Android P FloatingActionButton that's part of the com.google.android.material.floatingactionbutton.FloatingActionButton and I'm getting this warning: VisibilityAwareImageButton.setVisibility can only be called from the same library group (groupId=com.google.android.material) import com.google.android.material.floatingactionbutton.FloatingActionButton import android.view.View class MainActivity : AppCompatActivity() { lateinit var demoFab: FloatingActionButton

Navigating to preference fragment using navigation component

大兔子大兔子 提交于 2019-12-08 15:30:23
问题 I'm trying to migrate my medium sized app to the new Android navigation component. Currently, my app consists of the single activity and I'm planning on keeping it the same (for that matter); So, I'm facing this issue in which I have a settings fragment ( PreferenceFragment ) that can be navigated to, basically, from every other fragment. This navigation is made through a menu in the app bar, therefore onOptionsItemSelected (containing this navigation) is in the main activity. I'm having

Navigation Component: Cannot find NavController

拈花ヽ惹草 提交于 2019-12-08 13:34:32
问题 I am using Navigation Component for navigating in my app. It works fine inside fragments but it fails to find the nav host in the activity that holds the actual navigation host. I am trying to open a new fragment when the user clicks on FAB, which I included in Main activity's XML. When I call findNavController() it fails to find the controller. The nav host controller is in the XML layout. I can't understand why it fails to find it. MainActivity class MainActivity : AppCompatActivity(),

How to get size of Room list in onCreate/ on main thread?

左心房为你撑大大i 提交于 2019-12-07 23:43:40
问题 How can I easily get the count of the database size so I can then do the appropriate actions based on whether the DB is empty or not? I have an App DB, View Model, Repository, Dao, and all the other pieces, and my objects insert... But I cannot call in onCreate() the size of the list in the DB. When I ever try to get mAppDatabase.vehicleDao().getAll().getValue().size() , or mVehicleViewModel.getAll().getValue().size() , I get null pointer exceptions. However I know my objects are inserting

Unable to clear the back stack of all fragments with Navigation Components

倖福魔咒の 提交于 2019-12-07 13:11:49
问题 I am using the Android Navigation Components and am facing one weird issue. I am not able to clear the back stack for the up button, no matter what I tried. My Navigation graph looks like this: Let's take the LoginFragment for example, <fragment android:id="@+id/loginFragment" android:name="com.yashovardhan99.firebaselogin.LoginFragment" android:label="Login" tools:layout="@layout/fragment_login" > <action android:id="@+id/action_loginFragment_to_welcomeFragment" app:destination="@id

How to Setup Jetpack Navigation with material.BottomNavigationView

坚强是说给别人听的谎言 提交于 2019-12-06 19:46:19
问题 I am unable to setup Navigation component with com.google.android.material.bottomnavigation.BottomNavigationView it is giving an error. Here is the code that I am trying to use // Setup bottom navigation view NavigationUI.setupWithNavController( bottom_navigation_view, findNavController(R.id.main_nav_host_fragment) ) when I open the NavigationUI class, I note that it just accept the old android.support.design.widget.BottomNavigationView but I want to use the new one com.google.android

How to get lifecycle.coroutineScope with new androidx.lifecycle:*:2.2.0-alpha01

末鹿安然 提交于 2019-12-06 19:11:10
问题 On 7th May, 2019 androidx.lifecycle:*:2.2.0-alpha01 was released announcing: This release adds new features that adds support for Kotlin coroutines for Lifecycle and LiveData. Detailed documentation on them can be found here. On documentation it's mentioned that I can get the LifecycleScope : either via lifecycle.coroutineScope or lifecycleOwner.lifecycleScope properties But it seems that I'm not able to find none of them. My current dependencises are: def lifecycle_ver = "2.2.0-alpha01"

Room TypeConverter for map

北城以北 提交于 2019-12-06 12:55:35
How would you write TypeConverter for Map? My approach was to do it by Moshi class Converters() { val moshi = Moshi .Builder() .add(KotlinJsonAdapterFactory()) .build() val mapOfStringsType = Types.newParameterizedType(Map::class.java, String::class.java, String::class.java) val mapOfStringsAdapter = moshi.adapter<Map<String, String>>(mapOfStringsType) @TypeConverter fun stringToMap(data: String): Map<String, String> { return mapOfStringsAdapter.fromJson(data).orEmpty() } @TypeConverter fun mapToString(map: Map<String, String>): String { return mapOfStringsAdapter.toJson(map) } } However, it

How to get size of Room list in onCreate/ on main thread?

让人想犯罪 __ 提交于 2019-12-06 12:10:40
How can I easily get the count of the database size so I can then do the appropriate actions based on whether the DB is empty or not? I have an App DB, View Model, Repository, Dao, and all the other pieces, and my objects insert... But I cannot call in onCreate() the size of the list in the DB. When I ever try to get mAppDatabase.vehicleDao().getAll().getValue().size() , or mVehicleViewModel.getAll().getValue().size() , I get null pointer exceptions. However I know my objects are inserting because when I run an observable, I can log their information... but I cannot get the count on the main

Livedata returned by Room won't be triggered after GC

时间秒杀一切 提交于 2019-12-06 06:12:22
Our team are building a project with benefits from Android Jetpack. There are demo code showing the question we are facing. These code can be found at https://github.com/viseator/TestRoomLivedata I create a UserDao : @Dao interface UserDao { @Query("SELECT * FROM user WHERE uid = :uid LIMIT 1") fun findUserById(uid: String?): Single<User> @Query("SELECT * FROM user WHERE state = 1 LIMIT 1") fun findLoginUserWithObserve(): LiveData<User> @Query("SELECT * FROM user WHERE state =1 LIMIT 1") fun findLoginUser(): Single<User> @Update fun update(vararg user: User) } I also created a kotlin object to