Category : kotlin

I’m trying to create a ProductionRelease compile-time constant, so that R8 can omit our debugging codes in the final production apk. I hit a roadblock whereby the BuildConfig.DEBUG is not assignable to a const val. // MyApplication.kt companion object { const val isDebug = BuildConfig.DEBUG const val isProductionRelease = BuildConfig.FLAVOR == "production" && !BuildConfig.DEBUG } ..

Read more

I have the following in my viewModel fun getUsernamePassword(inputUserName:String, inputPassword:String):List<User> = viewModelScope.launch(Dispatchers.IO) { return repository.getUsernamePassword(inputUserName, inputPassword) } However, I am getting an error saying Type mismatch. Required: List<User> Found:Job What can I do to solve this error. The ultimate goal is to have the function run on a non-black thread operate and a part from ..

Read more

Until now I was using Flow and mapping it to LiveData like below – The MyService looks like this – override fun provideData(action: MyAction) = flow { emit(MyResult.Loading) emit(dataRepository.getNewData()) } The ViewModel looks like this – fun getData() = myService.provideData(MyAction.GetData).map { }.asLiveData(Dispatchers.Default + viewModelScope.coroutineContext) I want to move to StateFlow. How can I use emit ..

Read more

i’m making a counter app with android studio using Kotlin language. My code is working great in the MainActivity but when it comes to fragment it’s not working anymore. class HomeFragment : Fragment() { private lateinit var homeViewModel: HomeViewModel @SuppressLint("SetTextI18n") override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { /*homeViewModel = ViewModelProvider(this).get(HomeViewModel::class.java)*/ ..

Read more

I am creating an app with the BottomNavigationView and I added a listener with setOnNavigationItemSelectedListener but the function I provided is never called. Here is my code override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main_page) openNewFragment(PostsFragment()) setBottomBar() handleIntent(intent) } private fun setBottomBar() { println("setting nav bar") val navbar = findViewById<BottomNavigationView>(R.id.bottom_navigation) navbar.isEnabled = true navbar.selectedItemId = R.id.home_label ..

Read more