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

    06/25/2022, 10:31 PM
    How to make dialog components reusable in Jetpack Compose Can a dialog be altered to make its components reusable without having to type duplicate lines of code for multiple items. My list has more than one item. When I click the first list item (Starters), I want 'Starters' as the dialog title and the Screen.Starters.route navigation route to be used, whereas when I click the other list item (Desserts), I want 'Desserts' as the dialog title Screen.Starters.route navigation route to be used. enum class Items(@StringRes val textResId: Int) {...
  • u

    user

    06/26/2022, 1:11 AM
    Android - queryAndAggregateUsageStats returns empty map I am working on a requirement where I need to get the app usage every 15 mins. I am getting empty map. Please see below code. I guess INTERVAL_BEST interval type is not working for given timeframe. Any help will be appreciated. Thanks. fun getAppsUsageMap() { val manager: UsageStatsManager? = null val calendar = Calendar.getInstance() val startTime = calendar.timeInMillis; calendar.add(Calendar.MINUTE, -15) val endTime = calendar.timeInMillis;...
  • u

    user

    06/26/2022, 1:31 AM
    Pass data from multiple retrofit requests to one recycler view adapter I have two resources from which I would like to pass data to one recycler view adapter. The data should be displayed on CardView items as shown in the picture.

    how I would like to do itâ–¾

    First I make an asynchronous retrofit request to get all appointments. Based on the restaurant_key I make another request for each appointment to get more details about the restaurant. How can I pass this data combined to the adapter...
  • u

    user

    06/26/2022, 2:11 AM
    How to make a FlutterActivity be a MethodCallHandler? I made my FlutterActivity MainActivity a MethodCallHandler: class MainActivity: FlutterActivity(), MethodCallHandler { so I implemented onMethodCall. However, to be able to process method calls, still something is missing. This is how it's done in a Flutter plugin: class MyPlugin: FlutterPlugin { private lateinit var channel : MethodChannel private val LOG_TAG: String = "MyPlugin.kt" override fun onAttachedToEngine(@NonNull flutterPluginBinding: FlutterPlugin.FlutterPluginBinding)...
  • u

    user

    06/26/2022, 2:51 AM
    Deserialize/Serialize Map to Data class Is there an existing Kotlin API that can deserialize Map to a Kotlin data class? Example: From this map val msgData = remote.data val env = msgData["environment"] val img = msgData["bigImage"] val title = msgData["title"] val description = msgData["description"] val redirectLink = msgData["link"] To this data class data class SampleObject( val env: String, val img: String, val title: String, val description: String, val...
  • u

    user

    06/26/2022, 3:11 AM
    Type: dynamic Undefined name 'DefaultFirebaseOptions'. Try correcting the name to one that is defined, or defining the name This is my initial_bindings.dart. I am trying to integrate my app to firebase and I get this error everytime I try to run it through an emulator. import 'package:grabbit_v6/data/apiClient/api_client.dart'; import 'package:firebase_core/firebase_core.dart'; import '../../firebase_options.dart'; class InitialBindings extends Bindings { @override void dependencies() async { Get.put(PrefUtils()); Get.put(ApiClient()); Connectivity connectivity = Connectivity();...
  • u

    user

    06/26/2022, 3:11 AM
    How can split a string which include only one hyperlink into multiple segments in Kotlin? There is a string which include only one hyperlink, I hope to split it into multiple segments in Kotlin. How can do? Thanks! The follwoing is some sample source and target. Visit our website for the latest news -> a[0]="Visit our" a[1]="http://www.google.net" a[2]= "website" a[3]="for the latest news" Visit our website -> a[0]="Visit our" a[1]="http://www.google.net" a[2]= "website"...
  • u

    user

    06/26/2022, 5:31 AM
    Delete Items of Recycler View in Firebase Update the Screen I have a Recycler View that contains Boards(a data class) which are stored in Firebase, I want to Delete the Boards When I Swipe Left or Right on Them but I can't Figure out a Way to Do it, So it will be Very Helpful if Any One could Tell Me How To Do It or any Suggestion would be of Great Help, Thank You. My Adapter of Recycler View open class BoardItemAdapter(private val context: Context, private val list: ArrayList): RecyclerView.Adapter() { private var onClickListener:...
  • u

    user

    06/26/2022, 5:51 AM
    How to animate offset from pointer input I am trying to make a component with a collapsed and expanded state. When collapsed there is a single row of content, and 5 rows when expanded with a downward swipe. Any single row can be visible when the component is collapsed, depending on some criteria. After looking at the animation codelab, I have come up with the following composable, but I'm not sure how to add an offset animation...
  • u

    user

    06/26/2022, 6:11 AM
    How to share the THIS applications base.apk using Intent? I want to share my application using a share button inside it. Once the button is clicked it should get the base.apk from the package manager and then share it using Intents. Here is what I have so far: All UI is ready and working I have the following code to get the app and share it try { val pm = packageManager val ai = pm.getApplicationInfo(packageName, 0) val srcFile = File(ai.publicSourceDir) val share = Intent() share.action = Intent.ACTION_SEND share.type...
  • u

    user

    06/26/2022, 6:51 AM
    Can we do Speech Recognition and Video Capture in Android using camerax simultaneously? I want to implement an app that can convert text to speech and record videos (with audio) simultaneously. But when I am calling both function either one of them working (the recent one that has been called). Can anyone suggest some ways to implement these two together.
  • u

    user

    06/26/2022, 6:51 AM
    AndroidStudio: data not added after signed app I have developed an app with android studio.it is ok when install on virtual or real device with android studio.but if i generate the apk ,its data does not insert in to db. QuestionDao.tk: @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertAll(questions: List) SeedDatabaseWorker.tk: class SeedDatabaseWorker( context: Context, workParams: WorkerParameters ) : CoroutineWorker(context, workParams) { override suspend fun doWork(): Result = coroutineScope {...
  • u

    user

    06/26/2022, 7:11 AM
    Why this saveToken function is keep saving wrong email & password even responseMessage = false? How to fix this (Kotlin) this is my kotlin app school project. So, the problem is my saveToken function keep saving the wrong email and password. Here is example case, when user do login with wrong email and password, saveToken saving the login data and toast about wrong email/password will appear, and then user do login with correct email & password, user will succesfully login to main activity but saveToken function is not running. Error appear when reopen the app (starting from splashActivity), the app will send...
  • u

    user

    06/26/2022, 7:31 AM
    How do I create a JSON data class for this sample Here is the JSON sample and I need data classes for this sample. [ { "id": "a", "symbol": "tiger", "name": "Tiger", }, { "id": "b", "symbol": "dog", "name": "Dog", } ] I am able to auto generate the classes but working with it is something I am not able to understand. I am using Retrofit, Moshi and unable to receive the response when I make the GET call. Let me know in comments if you require the complete code.
  • u

    user

    06/26/2022, 8:11 AM
    Kotlin Retrofit return null to recylerView in .enqueue So I'm trying to get data from an API with retrofit into a recycler view adapter. Everything works perfectly such as showing a list of data retrieve into list items. However, when press on the list item of the recycler view and intent to another activity and intent back to the original activity, the app crashed. With the error below : E/AndroidRuntime: FATAL EXCEPTION: main Process: com.marcusneo.stockportfolio, PID: 7586 java.lang.NullPointerException at...
  • u

    user

    06/26/2022, 8:31 AM
    how to get data from dynamically created views I am pretty much a beginner in app development. I am creating a GPA calculator. I was able to create a button that would create a new EditText view for each time it was tapped. but I don't know how can get the values from those EditTexts separately so I can use them to calculate GPA. I looked up every similar question here and on the internet in general, but none of them helped me. Here is my code: activity_main.xml new_layout.xml...
  • u

    user

    06/26/2022, 9:11 AM
    How correct use NavBackStackEntry with alertDialog? I'm trying use backStackEntry to refresh parent fragment after in Dialog fragment pressed "Ok" button. trying to implement this according to the documentation Parent Fragment class EmployeesFragment : Fragment(R.layout.fragment_employees) { private val viewModel = EmployeesViewModel() override fun onViewCreated(view: View, savedInstanceState: Bundle?) {...
  • u

    user

    06/26/2022, 9:31 AM
    Creating JS library with kotlin multi platform and use it on angular 2 via npm I created and simple kotlin multi platform application and i want to use it on angular project via publishing on npm. Here is my build.gradle.kts file plugins { kotlin("multiplatform") kotlin("native.cocoapods") id("com.android.library") } version = "1.0" kotlin { android() iosX64() iosArm64() iosSimulatorArm64() js { browser { webpackTask { output.libraryTarget = "this" } binaries.executable()...
  • u

    user

    06/26/2022, 9:51 AM
    MiniMax always returning next empty cell After loosing the tree in the forest here I'am asking for directions. Trust me I have lost lot of my hair (had my hair cut) before decided to post this and know I am being silly here. My MiniMax code is always giving the next available cell. val engine = TTTEngine() engine.findBestMoveForO() Expected Output: CellPosition.TopEnd Actual Output: CellPosition.TopCenter (First Available Cell) The Code class TTTEngine { private var state = mutableMapOf() private var botPlayer: Player =...
  • u

    user

    06/26/2022, 9:51 AM
    Start intent activity from service android all) I have an issue 1. I have Fragment which start two foreground service SpeechListener, CallService: AndroidEntryPoint class TransmitterFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) if (ContextCompat.checkSelfPermission(requireContext(), "android.permission.RECORD_AUDIO")!=PackageManager.PERMISSION_GRANTED) {...
  • u

    user

    06/26/2022, 9:51 AM
    Why I am not able to link Multiple Auth Providers to an Firebase Account on Android Jetpack compose? I have sign in project in jetpack project so, I want to use phone authentication also in my project, so when I complete my process, in firebase providers section, my email and phone number not link, I read example question, and I added this line of code in my project val credential = PhoneAuthProvider.getCredential(verificationOtp, otp) auth.currentUser?.linkWithCredential(credential)...
  • u

    user

    06/26/2022, 9:51 AM
    How can I check whether a given string contains another substring? How can I check whether a given string contains another substring? fun isFieldRepeated(jsonIn: String, field:String): Boolean { var count: Int = 0; while (jsonIn.indexOf(field) > -1) { jsonIn = jsonIn.substring(jsonIn.indexOf(field)+field.length(),jsonIn.length()); count++; } if(count>1) return true; return false; }
  • u

    user

    06/26/2022, 10:11 AM
    Detecting Available Displays on an Android Device Using Kotlin As you know, some phones have external or secondary displays, for example Motorola's new foldable Razr phones, or Samsung's Z Flip 3. I was wondering if there was a way to access those displays programmatically using Kotlin, or simply just verifying their presence. The real reason I want information about this is because my Motorola Razr 2019 has an issue where the phone does not recognize the fold action, so the external display is never told to come on by the phone. I decided to write an...
  • u

    user

    06/26/2022, 10:31 AM
    Korge gradle setup for JVM target I want to try the Korge libs on the JVM. I used the Korge IntelliJ plugin to create a new project. My build.gradle.kts looks like this : import com.soywiz.korge.gradle.* buildscript { val korgePluginVersion: String by project repositories { mavenLocal() mavenCentral() google() maven { url = uri("https://plugins.gradle.org/m2/") } } dependencies { classpath("com.soywiz.korlibs.korge.plugins:korge-gradle-plugin:$korgePluginVersion") } } apply() korge...
  • u

    user

    06/26/2022, 10:31 AM
    Kotlin - StateFlow not emitting update to its collectors I got a StateFlow of type UserStateModel (data class) in my app. private val _userStateFlow: MutableStateFlow = MutableStateFlow(UserStateModel()) val userStateFlow: StateFlow = _userStateFlow here is the UserStateModel data class UserStateModel( val uid: String? = null, val username: String? = null, val profileImageUrl: String? = null, var isLoggedIn: Boolean = false, val isPremiumUser: Boolean = false, val posts: List? = listOf() ) When I update the StateFlow with...
  • u

    user

    06/26/2022, 10:31 AM
    Attribute android:[...] is not allowed here and things So, out of nowhere, all my .xml file started to have this error. It told me to sync gradle, but my gradle file also have a warning but there's nothing inside.

    Gradle Warningâ–¾

    I already tried the invalid caches solution , close/open the file ... None on these worked. PS: I can run my project without error. Can someone help me please ?
  • u

    user

    06/26/2022, 11:11 AM
    Can I search dB for list of items and return their IDs respectively? I have a data table like "animals" and I want to search for 5 animals at once (open connection once) and get their IDs respectively then close the connection one time only - for the sake of performance - instead of opening connection everytime and search for one animal and then close the connection and redo this times. Is there a way to do this
  • u

    user

    06/26/2022, 11:11 AM
    how to remove dynamically created EditTexts kotlin I am a beginner in app development. I want to create a GPA calculator. I was able to create a button that would create a new EditText view for each time it was tapped. but I don't know how I can remove them. removeView() only works for the first view, then stops working. Here is my code: activity_main.xml new_layout.xml MainActivity.kt package com.example.gpacalculator import androidx.appcompat.app.AppCompatActivity import...
  • u

    user

    06/26/2022, 11:31 AM
    Cant scroll to new item in RecyclerView I just want recycler view to scroll to last position when receiving message from StompClient. I am using StompClient library. And when i am getting new message i am updating RV Adapter, but i cant scroll it for some reason. I've tried postdelaying it but it worked only in OnClickListener, not in coroutine, in coroutine i am trying with withContext(Dispatchers.Main) but it is not working as well.

    https://i.stack.imgur.com/BCHnI.pngâ–¾

  • u

    user

    06/26/2022, 11:31 AM
    How do I set the socketTimeout in ktor? I tried val socket = aSocket(ActorSelectorManager(Dispatchers.IO)).tcp().configure { socketTimeout = 1000 } .connect("127.0.0.1", 2323) I can set other values like this but not the timeout. It's listed here TCPClientSocketOptions
Powered by Linen
Title
u

user

06/26/2022, 11:31 AM
How do I set the socketTimeout in ktor? I tried val socket = aSocket(ActorSelectorManager(Dispatchers.IO)).tcp().configure { socketTimeout = 1000 } .connect("127.0.0.1", 2323) I can set other values like this but not the timeout. It's listed here TCPClientSocketOptions
View count: 8