Questions tagged [kotlin-android-extensions]

Questions related to Kotlin Android Extensions

Kotlin Android Extensions

721 questions
5
votes
1 answer

Returning a Kotlin result in a coroutine context throws an exception

I have a simple setting: lifecycleScope.launch { val result = test() } suspend fun test(): Result = withContext(Dispatchers.IO) { Result.failure(IllegalStateException("QWER")) } Actual result: The code above is crashing…
5
votes
1 answer

How can I share a Surface between MediaCodec encoder and CameraX

I want to get the images from CameraX (Preview Use case) and encode them as h.264 Video using MediaCodec. How can I achieve this ? What I was trying was, to use the Surface returned from MediaCodec.createInputSurface() in Preview.Builder() by using…
5
votes
2 answers

How does thread synchronization work in Kotlin?

I have been experimenting with Kotlin synchronization and I do not understand from the docs on how the locking mechanism works on thread synchronization over common resources and thus attempted to write this piece of code which further complicates…
5
votes
2 answers

Private members variables in Data Class in Kotlin

I am new to kotlin and when I was reading about the data classes in kotlin and I found these code.Its basically a comparision between the java model class and kotlin data class and it was wriiten over there that both the code do the same task. Code…
5
votes
1 answer

what is the difference between lazy and lazyFast in kotlin?

what is the difference between Kotlin's lazy delegate property lazy and lazyFast?.because it looks like same code. private val key: String by lazy { if (arguments != null && arguments?.getString(Constants.KEY) != null) { …
5
votes
1 answer

Is it possible in one Java file to mix Java code and Kotlin code

Android Studio 3.4.2 in build.gradle: buildscript { ext.kotlin_version = '1.3.41' repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.4.2' classpath…
Alex
  • 1,857
  • 4
  • 17
  • 34
5
votes
2 answers

Where to find the liveData building block?

https://developer.android.com/topic/libraries/architecture/coroutines Android coroutines plus liveData documentation states that we can use the liveData builder function in case we want to want to perform async operations inside the live data…
Ninja420
  • 3,542
  • 3
  • 22
  • 34
5
votes
1 answer

Is there a way in Kotlin to combine an inline function and a when expression with an extension function?

I would like to reduce the size of an if-elseif-else ladder but can't use just when because the smartcast doesn't catch the cases I'm dealing with. I'm wondering if I can combine something like a let or an also and a when into a single inline…
5
votes
3 answers

How to make Alert dialog items?

I want to create alert dialog items. Here is my code. val colors = arrayOf("Red","Green","Blue") val builder = AlertDialog.Builder(this) builder.setTitle("Pick a color") builder.setItems(colors) {_,_ -> …
user10413212
5
votes
2 answers

'return' is not allowed here: Kotlin Coroutine launch(UI) block

fun onYesClicked(view: View) { launch(UI) { val res = post(context!!,"deleteRepo") if(res!=null){ fetchCatalog(context!!) catalogActivityCatalog?.refresh() } } } Above code is working fine.…
5
votes
2 answers

Parcelize complains "Parcelable should be a class" on objects and enums

When I try to annotate an enum class or object with @Parcelize, it results in the error 'Parcelable' should be a class, both as an editor hint and as a compile failure. I can @Parcelize classes just fine, but I can't do things like @Parcelize object…
Leo Aso
  • 11,898
  • 3
  • 25
  • 46
5
votes
1 answer

onSaveInstanceState called after onDestroyView

I'm dealing here with strange fragment lifecycle behavior. I have an activity that host two fragments: CityFragment - to display cities list and WeatherFragment - to display the weather forecast for selected city. When the app starts CityFragment is…
5
votes
1 answer

Not satisfied: inferred type T? is not subtype of Any

To map the result I have implemented sealed generic class : public sealed class ResultMapper { public class Ok(public val value: T, override val response: Response) : Result(),…
QuokMoon
  • 4,387
  • 4
  • 26
  • 50
5
votes
1 answer

Java and Kotlin combined build error (Duplicate Zip Entry)

I have added Kotlin library to my existing project. After that I'm getting the build error. I commented all the recently added libraries and checked the main problem is after adding kotlin library Error:Execution failed for task…
5
votes
1 answer

lateinit property adapter has not been initialized in Kotlin4Android

I have created RecyclerView in fragment inside activity, all are working good but when i do notifyDataSetChanged() to adapter from activity through interface,I got an error "lateinit property adapter has not been initialized" but I have already…