https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
stackoverflow
  • u

    user

    07/14/2022, 4:31 PM
    Kotlin. How to use generic types with lambda? I'm using function type onError: class Status( private val onError: (T) -> Unit ) I need to make my lambda argument covariance (with out)? Is it possible ?
  • u

    user

    07/14/2022, 5:11 PM
    How to update livedata through a method with multiple parameters I have this livedata "events" that should be updated if the method loadEvents() gets fired. The thing is, I need to pass many different parameters to that method. If I call this method and then observe the data, the data is null. How can I do this? Viewmodel: private val _events = MutableLiveData() val events: LiveData get() = _events fun loadEvents( dateTo: String, dateFrom: String?, dateTime: String?,...
  • u

    user

    07/14/2022, 5:31 PM
    Does Switching off the Android Phone destroys the activity? I was playing with the activity life cycle today. I had logged all the lifecycle methods. I was on the MainActivity and then switched off the phone suddenly. I noticed 2 methods being called: onPause, onStop, but onDestroy never got called. Any take on this?
  • u

    user

    07/14/2022, 5:31 PM
    App crash after interegrating firebase authentication in my app My app crashes on starting it (basically any activity with firebase code) after adding firebase authentication This is the logcat 2022-07-14 20:17:21.538 15482-15482/com.example.flimer E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.flimer, PID: 15482 java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.flimer/com.example.flimer.SignUp}: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.pm.ApplicationInfo...
  • u

    user

    07/14/2022, 5:51 PM
    How to add a RecyclerView in a fragment Kotlin- I initialize the dataset but idk what to to with context ItemAdapter: class ItemAdapter( val context: Context, val dataset: List) : RecyclerView.Adapter() { Fragment: val dataset: List =ArrayList() val context: Context = //so i can initialize the-> adapter= ItemAdapter(context, dataset)
  • u

    user

    07/14/2022, 6:11 PM
    How can I fake dagger injection for Instrumented test in dynamic-feature modules? I have a simple Note Taking Application. The Application has an app gradle module and editnote gradle dynamic feature-module. Hence my editnote gradle module will depend on app gradle module [because feature-module is not not resolved at the compile time] My app contains an ApplicationModule dagger module and ApplicationComponent. Similarly my editnote contains EditNoteModule and EditNoteComponent. @Module open class EditScreenModule { @Provides @Named("TutorialText") open fun...
  • u

    user

    07/14/2022, 6:31 PM
    Why android room database query doesn't work What I am doing wrong? Model class @Entity(indices = [Index(value = [ "id_mess"], unique = true)]) class MessengerModel ( @PrimaryKey @ColumnInfo(name = "id_mess") var id_mess: Int, var id_fr: Int, var id_to: Int, var dt: Long, var message: String ) ModelDao class @Query("SELECT * FROM MessengerModel WHERE ( (id_fr = :his_id AND id_to = $MY_USER_ID) OR (id_fr = $MY_USER_ID AND id_to = :his_id) ) AND id_mess < :id_message") fun...
  • u

    user

    07/14/2022, 6:51 PM
    ClassCastException when using Mockito.thenAnswer I am new to Kotlin. I get exception when trying to use Mockito's thenAnswer method Controller: @RestController class SampleRestController( val sampleService: SampleService ) { @PostMapping(value = ["/sample-endpoint"], consumes = [MediaType.APPLICATION_JSON_VALUE], produces = [MediaType.APPLICATION_JSON_VALUE]) fun sampleEndpoint(@RequestBody values: List): ResponseEntity { val response = sampleService.serviceCall(values) return...
  • u

    user

    07/14/2022, 6:51 PM
    How can I merge layouts in scrolview? I am using scrollview as horizantal and vertical. I have two child layouts, I want to add them in this scrollview. Like in the picture, spinners are inside of edittexts, actually I want to add them next to them just vertically. How can I execute this?

    screenshot1▾

    for(i in 1..rows) { for(i in 1..colomns)...
  • u

    user

    07/14/2022, 6:51 PM
    CopytoClipboard not working in Adapter to show in recyclerview I have a recyclerview with adapter (to show external strings)and I'm trying to click a button "copy" so that it copies the strings in view to the clipboard. CardLayout.xml Button to use as copy button is android:id="@+id/copyactivity" And this is my TaskAdapter.kt package com.example.what2do_v6.Adapter import android.content.ClipData import android.content.ClipboardManager import...
  • u

    user

    07/14/2022, 7:31 PM
    Activity never becomes requested state "[CREATED, RESUMED, DESTROYED, STARTED]" (last lifecycle transition = "PRE_ON_CREATE") I'm taking a Android Basics in Kotlin course and I'm stuck in this codelab: <a href="https://developer.android.com/codelabs/android-basics-kotlin-affirmations-test-lists-and-adapters?continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-kotlin-unit-2-pathway-3%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fandroid-basics-kotlin-affirmations-test-lists-and-adapters" rel="nofollow...
  • u

    user

    07/14/2022, 7:31 PM
    If statement not working yet used correctly class SignUp : AppCompatActivity() { private lateinit var auth: FirebaseAuth private var etEmail: String? = null private var etPass: String? = null private var etPass2: String? = null private lateinit var btn: Button override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_sign_up) // Initialising auth= Firebase.auth etEmail = findViewById(R.id.et_email).text.toString().trim() etPass =...
  • u

    user

    07/14/2022, 8:31 PM
    I have to turn the date that comes from API to this format " starts in 10 days 23 h 34 m" from this format "2022-07-24T05:32:05.000000Z" I understand how to format in other forms but I don't know how to format in this way. @SuppressLint("SimpleDateFormat") fun String.toDateMixedString(from: String = "yyyy-MM-dd'T'hh🇲🇲ss.000000'Z'", to: String = "MM/dd/yyyy"): String { val date = this.toDate(from) val c = Calendar.getInstance() date?.let { c.time = it } val day = c.get(Calendar.DAY_OF_MONTH) val year = c.get(Calendar.YEAR) val monthText = c.getDisplayName(Calendar.MONTH, Calendar.SHORT, Locale.US)...
  • u

    user

    07/14/2022, 8:31 PM
    How can i iterate Arraylist of an object in Kotlin? I have a arrayList of an object , and i cannot iterate my list forward or reward , i don't want to display my message in these case but it does . private fun handleLivePopUp() { // vous êtes en direct val id = presenter.programItems?.indexOf(presenter.currentProgram) // val it = presenter.programItems?.listIterator() // val previous = if (id == 0) presenter.programItems!!.size - 1 else id?.minus(1) if (id != null){ if(id == 0){ //si liste ==...
  • u

    user

    07/14/2022, 8:51 PM
    How not get out of bound in Kotlin? I got the code that compare current element with the next element in array. But it crashes with out of bound because I guess when its on the last element there is no next element to compare with so it crashes.How to handle this to avoid crash and stop comparing on the last element? Here is my code fun myFunction(arr: Array): Int{ if (arr.isEmpty()) return 0 var result = 0 for (item in arr.indices) { if (arr[item] > 0 && arr[item + 1] < 0){...
  • u

    user

    07/14/2022, 9:11 PM
    What are the use cases for AtomicFile? I'm having trouble understanding the use cases for AtomicFile. Since it does not confer any thread safety, is it just for ensuring no partial/invalid files are written if the app crashes or device loses power during a file write? What would be the purpose of reading a file with AtomicFile?
  • u

    user

    07/14/2022, 9:51 PM
    Update firestore data from populated recycler View I want to update firestore data which I have got in a Recycler view. Recycler View Activity Code class AdminActivity : AppCompatActivity() { private val dB = Firebase.firestore private lateinit var userRecyclerView: RecyclerView override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) supportActionBar?.title = "Admin Panel" userRecyclerView = findViewById(R.id.user_list)...
  • u

    user

    07/14/2022, 10:11 PM
    I need it redirect to new page after clicking in listview I am designing a guide application. When I click on the person I selected from the list, it should go to the profile page I prepared. I will be very happy if you can help :)

    https://i.stack.imgur.com/AANpq.png▾

  • u

    user

    07/14/2022, 10:11 PM
    How to download HLS audio in Android I would like to download HLS audio stored in my server using Exoplayer or any other mechanism.. Also once the audio is downloaded I would like to encrypt it. Can anyone please tell me how do I achieve it. I have read most of the article but could not find any help.
  • u

    user

    07/14/2022, 10:31 PM
    How to make item appear in the center of the screen Jetpack Compose when using LazyRow or Column? I have been trying to make it so that the first item on a LazyRow is centered in the middle of the screen. LazyRow with snapper and infinite scrolling @OptIn(ExperimentalSnapperApi::class) @Composable fun CircularList( data: List, modifier: Modifier = Modifier, isEndless: Boolean = true ) { val listState = rememberLazyListState( if (isEndless) Int.MAX_VALUE / 2 else 0 ) val configuration = LocalConfiguration.current val screenWidth =...
  • u

    user

    07/15/2022, 12:11 AM
    Button android studio, how to create a button that stops setonclicklistener function? I have a button such as I have created a setOnClickListener method and inside their is a loop. val btnClickMe1 = findViewById(R.id.button) btnClickMe1.setOnClickListener { //do something here 20 times } This method works fine, however, I have created a .apk file. When I click the button the function runs. I want to know how I can exit the loop by clicking the same button. Regardless of whether or not the loop has...
  • u

    user

    07/15/2022, 12:11 AM
    Using cookies in Exoplayer streams I'm trying to stream content from a url that returns a 404 if you're not logged in or a 302 redirect if you are. To log in, I need to pass a cookie in the headers for Exoplayer's requests, but I'm struggling to work out how. Previous answers suggest using a default Cookie Manager instance with your cookies already set. Others suggest setting the header as a map in HttpDataFactory.setDefaultRequestProperty. Neither have worked for me. Here's my working so far. val cookieManager =...
  • u

    user

    07/15/2022, 2:11 AM
    Apk development code - &lt;application android:name= "com.example.nameofapp.BaseApplication"&gt; how is it included in the project or the libraries? Good afternoon, im new to app development and I would like to see if there is someone who can give me like a tip or advice on this particular problem. Basically this apk is going to use features from another apk and I think I understand how it's integrated inside the code, for example: '''
  • u

    user

    07/15/2022, 3:51 AM
    while i made plugin with kotiln this error occur but i dont know what is the problem in running server this is the code package com.github.noonmaru.aimless.plugin import com.comphenix.protocol.PacketType import com.comphenix.protocol.ProtocolLibrary import com.comphenix.protocol.events.PacketContainer import com.comphenix.protocol.wrappers.EnumWrappers import com.comphenix.protocol.wrappers.PlayerInfoData import com.comphenix.protocol.wrappers.WrappedChatComponent import com.comphenix.protocol.wrappers.WrappedGameProfile import org.bukkit.Bukkit import org.bukkit.entity.Player object...
  • u

    user

    07/15/2022, 4:11 AM
    Intent.createChooser not working for sharing image in REDMI xiomi devices Intent.createChooser not working for sharing image in REDMI devices I am saving image locally in my external storage of device and then passing the URI of that image in Intent.putExtra(Intent.EXTRA_STREAM, uri) and MIME type as image/jpg and then using Intent.createChooser . It works perfectly in all android devices but in REDMI devices the image get stored but I dont see the options menu for social media apps.... First I am calling share image and from which I am calling saveMediaToStorage...
  • u

    user

    07/15/2022, 6:31 AM
    Validate valid phone number entry I want to figure out invalid phone numbers entered in edittext before hitting the OTP api. Invalid phone numbers pattern may looks like these patterns +91-0000000000 / +91-0000000011 / +91-1234567890 ...and so on. Already added a check to validate invalid phone number but it didn't helps in detecting invalid patterns of phone numbers which can't exist. private boolean isValidMobile(String phone) { return android.util.Patterns.PHONE.matcher(phone).matches(); } Anyone please suggest how...
  • u

    user

    07/15/2022, 6:31 AM
    How to implement Copy of image and text to Clipboard in Android I am developing an App in which I require a functionality of copy of text and also Image whichever the user wants and paste it in app . so far I have accomplished the copy and paste of text data and also I have successfully copied the Image to clipboard but my application is not showing the copied image in keyboard like below also I don't know how to handle after the image shows in keyboard in my application and the user clicks on it in my app. <a href="

    https://i.stack.imgur.com/Mbz7j.png▾

    "...
  • u

    user

    07/15/2022, 7:11 AM
    Get Person's shirt color using Pose Detection(Android) I am developing an app where I want to detect the color of the person's shirt using pose detection. val allPoseLandmarks = pose.getAllPoseLandmarks() val leftShoulder = pose.getPoseLandmark(PoseLandmark.LEFT_SHOULDER) val rightShoulder = pose.getPoseLandmark(PoseLandmark.RIGHT_SHOULDER) val leftElbow = pose.getPoseLandmark(PoseLandmark.LEFT_ELBOW) val rightElbow = pose.getPoseLandmark(PoseLandmark.RIGHT_ELBOW) val leftWrist = pose.getPoseLandmark(PoseLandmark.LEFT_WRIST) val rightWrist =...
  • u

    user

    07/15/2022, 7:11 AM
    How to draw on a relative layout? I know it is only possible to draw on a canvas, however, my situation does not allow me to do as such(or maybe I do not know how to do it.) In any case, this is the video that I have followed, it is very simple, which teaches how to draw based on touch inputs on a canvas. (

    https://www.youtube.com/watch?v=r8zAQTa2rfE▾

    ) This is the most commonly used method to draw, by having 2 classes, 1 which extends View(so as...
  • u

    user

    07/15/2022, 7:11 AM
    Add var from .kt in activity main i had a QR Scanner from the internet. But my Kotin skills are not available... How can I add a COUNTER, that count my times, I scaned a code?

    code of counter▾

    Now I want to see that counter in the activity main. But how can I put a Text to that?

    enter image description here▾

Powered by Linen
Title
u

user

07/15/2022, 7:11 AM
Add var from .kt in activity main i had a QR Scanner from the internet. But my Kotin skills are not available... How can I add a COUNTER, that count my times, I scaned a code?

code of counter▾

Now I want to see that counter in the activity main. But how can I put a Text to that?

enter image description here▾

View count: 5