Manually clearing an Android ViewModel?

Quick solution without having to use Navigation Component library: getActivity().getViewModelStore().clear(); This will solve this problem without incorporating the Navigation Component library. It’s also a simple one line of code. It will clear out those ViewModels that are shared between Fragments via the Activity

How to get a result from fragment using Navigation Architecture Component?

They have added a fix for this in the 2.3.0-alpha02 release. If navigating from Fragment A to Fragment B and A needs a result from B: findNavController().currentBackStackEntry?.savedStateHandle?.getLiveData<Type>(“key”)?.observe(viewLifecycleOwner) {result -> // Do something with the result. } If on Fragment B and need to set the result: findNavController().previousBackStackEntry?.savedStateHandle?.set(“key”, result) I ended up creating two extensions for … Read more

Jetpack Compose – Column – Gravity center

You can use these parameters: horizontalAlignment = the horizontal gravity of the layout’s children. verticalArrangement= the vertical arrangement of the layout’s children Something like: Column( modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally ) { Text( text = “First item”, modifier = Modifier.padding(16.dp) ) Text( text = “Second item”, modifier = Modifier.padding(16.dp) ) Text( … Read more

Can I use library that used android support with Androidx projects.

You can enable Jetifier on your project, which will basically exchange the Android Support Library dependencies in your project dependencies with AndroidX-ones. (e.g. Your Lottie dependencies will be changed from Support to AnroidX) From the Android Studio Documentation (https://developer.android.com/studio/preview/features/): The Android Gradle plugin provides the following global flags that you can set in your gradle.properties … Read more

Fragments destroyed / recreated with Jetpack’s Android Navigation components

Ian Lake from google replied me that we can store the view in a variable and instead of inflating a new layout, just return the instance of pre-stored view on onCreateView() Source: https://twitter.com/ianhlake/status/1103522856535638016 Leakcanary may show this as leak but its false positive..

Android : Difference between DataBinding and ViewBinding

According to the official docs: ViewBinding Only binding views to code. DataBinding Binding data (from code) to views + ViewBinding (Binding views to code) There are three important differences With view binding, the layouts do not need a layout tag You can’t use viewbinding to bind layouts with data in xml (No binding expressions, no … Read more

Type ‘State’ has no method ‘getValue(Nothing?, KProperty)’ and thus it cannot serve as a delegate

If you get a compiler error that observeAsState or getValue are not defined make sure you have the following imports: import androidx.compose.runtime.getValue import androidx.compose.runtime.livedata.observeAsState This information is from Step #4 in the “Using State in Jetpack Compose” codelab.

how to get viewModel by viewModels? (fragment-ktx)

Atlast we we have got stable version. After moving to implementation ‘androidx.fragment:fragment-ktx:1.1.0’ i faced another issue. ###Compiler Error: Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6 ###build.gradle (Module:app) compileOptions { sourceCompatibility = 1.8 targetCompatibility = 1.8 } kotlinOptions { jvmTarget = “1.8” } reference After … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)