Questions tagged [android-jetpack]

Android Jetpack is a Google's set of libraries, tools and architectural guidance to build Android apps and provides common infrastructure code.

Android Jetpack is the next generation of Android components, bringing together the benefits of the Support Library -- backwards compatibility and immediate updates -- to a larger set of components, making it quick and easy to build robust, high quality apps.

It manages activities like background tasks, navigation, and lifecycle management, so you can eliminate boilerplate code and focus on what makes your app great.

It is designed to work well with Kotlin, saving you even more code with Android KTX. The new Android Jetpack components released today include WorkManager, Paging, Navigation, and Slices.

Useful Links

2879 questions
309
votes
10 answers

What is AndroidX?

I am reading about a room library of Android. I see they changed package android to androidx. I did not understand that. Can someone explain, please? implementation "androidx.room:room-runtime:$room_version" annotationProcessor…
175
votes
13 answers

Type 'State?>' has no method 'getValue(Nothing?, KProperty<*>)' and thus it cannot serve as a delegate

I'm trying to get a value from LiveData with observeAsState in jetpack compose, but I get a weird error Type 'State' has no method 'getValue(Nothing?, KProperty<*>)' and thus it cannot serve as a delegate Code @Composable fun…
SNM
  • 5,625
  • 9
  • 28
  • 77
166
votes
12 answers

How to get Context in Jetpack Compose

fun createListItem(itemIndex: Int) { Padding(left = 8.dp, right = 8.dp, top = 8.dp, bottom = 8.dp) { FlexRow(crossAxisAlignment = CrossAxisAlignment.Center) { expanded(1.0f) { Text("Item $itemIndex") …
163
votes
38 answers

Android Navigation Architecture Component - Get current visible fragment

Before trying the Navigation component I used to manually do fragment transactions and used the fragment tag in order to fetch the current fragment. val fragment:MyFragment = supportFragmentManager.findFragmentByTag(tag):MyFragment Now in my main…
Alin
  • 14,809
  • 40
  • 129
  • 218
152
votes
8 answers

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

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…
Kyle Falconer
  • 8,302
  • 6
  • 48
  • 68
151
votes
32 answers

Handling back button in Android Navigation Component

I'd like to know how properly handle system back button action using Navigation Controller. In my app I have two fragments (for ex. fragment1 and fragment2) and I have an action in fragment1 with destination to fragment2. Everything works well…
Kiryl Tkach
  • 3,118
  • 5
  • 20
  • 36
148
votes
28 answers

Safeargs library doesnt generate direction class

I use navigation library and safeargs for passing data. I define argument to fragment like that.
6155031
  • 4,171
  • 6
  • 27
  • 56
143
votes
13 answers

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

I am working with Single viewModel for the Activity and all of its fragment. So to initialise viewmodel if have to write this setup code in onActivityCreated of all the fragment's override fun onActivityCreated(savedInstanceState: Bundle?) { …
142
votes
18 answers

Jetpack Compose - Column - Gravity center

I'm creating a layout with Jetpack Compose and there is a column. I would like center items inside this column: Column(modifier = ExpandedWidth) { Text(text = item.title) Text(text = item.description) }
128
votes
4 answers

Android : Difference between DataBinding and ViewBinding

We are using DataBinding since Jetpack release. Android documentation indicates that ViewBinding was added in Android Studio 3.6 Canary 11+. I read the documentation but its looks similar to DataBinding. Can anyone explain what's the difference…
120
votes
10 answers

Fragments destroyed / recreated with Jetpack's Android Navigation components

I'm trying to implement Navigation with Jetpack's architecture components in my existing app. I have a single activity app where the main fragment (ListFragment) is a list of items. Currently, when the user taps on a list item a second fragment is…
115
votes
15 answers

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

I know, androidx and support dependency causing multidex error We can not use androidx and android support at a same time. So I totally migrate to androidx. but one of my dependency lib used android support "lottie". What can we do in above…
Hitesh Dhamshaniya
  • 2,088
  • 2
  • 16
  • 23
115
votes
9 answers

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

Let's say that we have two fragments: MainFragment and SelectionFragment. The second one is build for selecting some object, e.g. an integer. There are different approaches in receiving result from this second fragment like callbacks, buses etc.…
103
votes
12 answers

Manually clearing an Android ViewModel?

Edit: This question is a bit out of date now that Google has given us the ability to scope ViewModel to navigation graphs. The better approach (rather than trying to clear activity-scoped models) would be to create specific navigation graphs for the…
96
votes
7 answers

How to disable ripple effect when clicking in Jetpack Compose

In Jetpack Compose, when you enable clickable {} on a modifier for a composable, by default it enables ripple effect for it. How to disable this behavior? Example code Row(modifier = Modifier .clickable { // action } )
ImMathan
  • 3,911
  • 4
  • 29
  • 45
1
2 3
99 100