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/05/2022, 9:51 AM
    Facebook SDK (Android): events can be seen in 'test events' debug view but are not reported in campaign manager When I test my app (either by launching it from Android Studio or the app in production on Google Play), I see the events in in 'test events' debug of the Facebook console, as can be seen here:

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

    Nevertheless, no installs are reported in the AdsManager (but I know that I have installs from my Facebook campaigns even if the CPI increased dramatically). Any idea how to solve this problem ?
  • u

    user

    07/05/2022, 9:51 AM
    How navigate from nested fragment I have a fragment that has a FragmentContainerView, and when I try to navigate from a nested fragment, I get an error Navigation action/destination cannot be found from the current destination Destination. When trying to navigate from the fragment in which the FragmentContainerView lies, everything works. How I can fix it ? navigation attempt override fun onEditPressed() { //error navigate(...
  • u

    user

    07/05/2022, 9:51 AM
    Glide not loading non image link I want to load this image link but It's not a .jpg or .png link so Glide can't load it. Is there any way to load this image? https://stg-congdan.vnptbinhphuoc.vn/web/image?model=citizen.hotline.category&id=1&field=logo Glide.with(this.context) //...
  • u

    user

    07/05/2022, 9:51 AM
    How to get a username on GitHub by token I am writing an android application on kotlin to view the user's repositories on GitHub, only a token is entered for authorization, according to which you need to get a username. Please help me write a request via retrofit
  • u

    user

    07/05/2022, 9:51 AM
    Best practice to call a variable from ViewModel I have this variable in my ViewModel: private String chosenDay; and when I want to set the chosen day I use setter function: public void setChosenDate(String date){ chosenDay = date; } and when I want to use it,I use getter: public String getChosenDay(){ return chosenDay; } My question is: Do you think its a good practice to use getter and setters for the viewModel or I can just access the variable directly from the activity? viewModel.chosenDay = "Monday" Thank you !
  • u

    user

    07/05/2022, 10:11 AM
    How to prohibit accepting values other than true and false in request for Kotlin Spring Boot what decorator can I put on the class field so that values other than true and false are not accepted in the request. now any values can go into the request, including boolean. I can send false, 0 and an empty string - it will be interpreted as false. I can send true, all positive and negative numbers and it will be interpreted as true. what can I do to accept only true and false? open class KdInfo : Info { @Min(0) var brutto: Long = 0 @NotNull var isRefund: Boolean = false...
  • u

    user

    07/05/2022, 10:11 AM
    Why does `EffectScope.shift` need the type parameter `B`? The move to the new continuations API in Arrow brought with it a handy new function: shift, in theory letting me get rid of ensure(false) { NewError() } or NewError().left().bind() constructs. But I'm not sure how to properly use it. The documentation states that it is intended to short-circuit the continuation, and there are no conditionals, so it should always take the parameter, and (in either parlance) "make it a left value", and exit the scope. So what is the type parameter B intended to...
  • u

    user

    07/05/2022, 10:31 AM
    Android Room entities with the same fields (TMDB API) I have several entities of the same type (same fields, names). How can I use one entity to handle all data of a given type? For example, I have UpcomingMovieEntity and PopularMovieEntity, and these entities are the same: @Entity(tableName = TABLE_UPCOMING_MOVIES) data class UpcomingMovieEntity( @PrimaryKey(autoGenerate = false) @ColumnInfo(name = "id") val id: Int, @ColumnInfo(name = "poster_path") val posterPath: String?, @ColumnInfo(name = "adult") val adult: Boolean,...
  • u

    user

    07/05/2022, 10:51 AM
    when I run my project the buttoms situation changes todays when i make a project and design it all of the situasion of buttoms in android studio is OK but when I run it the buttoms situation changes can any one help me?
  • u

    user

    07/05/2022, 10:51 AM
    How to set default value for string in attributes at declare-styleable I'm setting some attributes with declare-styleable to make a custom view. One of this attributes is a string. What I want to do, is that if I dont set a value in XML for thiks attribute, give it a default value but I don't know how to do it. In my custom view Im doing this: private var title = "" init{ val styledAttr = context.obtainStyledAttributes(attrs,R.styleable.MyCustomView) title = styledAttr.getString(R.styleable.MyCustomView_title)!! //I cant remove "!!" or I get...
  • u

    user

    07/05/2022, 11:11 AM
    Android Compose How to scale and rotate an image via other button

    screenshotâ–¾

    I'm trying to make a photo editor that can be scale, rotate and drag to any place. But I want to control the scale and rotate behavior via the corner rotate icon not by the image itself. I know it must to be using pointerInput from the modifier, but not sure how to implement it. Can anybody help with that and give some example?
  • u

    user

    07/05/2022, 11:31 AM
    Why Spring Boot app dies regularly after several days of uptime I have a Kotlin Spring Boot app and scheduled job inside: @Scheduled(cron = "\${cronjob.activate.cron}", zone = "\${cronjob.activate.zone}") fun activate() { log.info("[Activation Cron Job] Triggered") while (!Thread.interrupted()) { val metadata = initMetadataWithActivationMetric() activationJobService.findRowsToActivate() //finds rows in postgresql depending on column that contains status value = IN_PROGRESS .takeUnless(List::isEmpty) ?.run...
  • u

    user

    07/05/2022, 11:51 AM
    How to get selection in MaterialButtonToggleGroup from inside Recycler View? I have a toggle group in a xml layout that is put into a recycler view This is backed by a viewmodel class ModeViewModel(val modes: Array) : ItemViewModel { override val layoutId: Int = R.layout.item_mode override val viewType: Int = DetailsViewModel.MODE_ITEM } And handled with an adapter class BindableRecyclerViewAdapter : RecyclerView.Adapter() { var itemViewModels: List = emptyList() private val...
  • u

    user

    07/05/2022, 11:51 AM
    How to implement foreground service on android version less than android Oreo(O) using Kotlin I am collecting raw sensor data (HeartRate, accelerometer, gyroscope, etc.) with Samsung Watch 4 which has Android version 6. I need to run my data collection application continuously in the background. However, it seems the watch OS kills the application after some time. So I need to implement a foreground service to keep the app running. The problem is foreground services work above android version 8. So my question is - How can I implement a foreground service on the android version 6...
  • u

    user

    07/05/2022, 12:11 PM
    Hoe can we get access token in kotlin? I'm new in kotlin and API. I wanna update profile in server, but the access token is required before update profile. Do you have any tutorial about access token?

    access token is requiredâ–¾

    Thank you for answering.
  • u

    user

    07/05/2022, 12:11 PM
    Custom lint rule to detect close-able resources which are not opened in a try-with-resources statement I want to write a custom lint rule so that it detects close-able resources which are not using (a) try-with-resources statement in java or (b) use extension in kotlin. Not sure where to start from as the examples I found are pretty basic like <a...
  • u

    user

    07/05/2022, 12:11 PM
    Saving some data in Kotlin fragments I have 2 fragments, first(start_fragment) should shows when app starts and have 2 buttons, 1 which close app(declineButton), and second which hide this fragment and show main fragment(webview_fragment). If user press agreeButton, next time app will starts already in main fragment(webview_fragment). How could i save that user press agree button? I tried to create boolean variable but can't imagine how can i put new value from button within fragment to variable within mainactivity....
  • u

    user

    07/05/2022, 12:11 PM
    How to add a dismiss on a listener argument in a AlertDialog I'm doing a method to create a custom AlertDialog in which I can call this method passing text, and listener to open a dialog in everywhere. My problem is that when I'm use it, I need to call a dismiss in every button of the custom view, but when I call this method the system no need to know anything about the dialog. So, I need to add a "dismiss" on the passed listener or something like that. private fun showCustomAlertDialog(context: Context, title: String?, message: String?,...
  • u

    user

    07/05/2022, 12:31 PM
    Is it allowed to put ActivityContext/ApplicationContext in a variable? Please tell me is it allowed to put ActivityContext/ApplicationContext in a variable as shown in the code below? class MainActivity : Activity() { private val context = applicationContext override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) } } As you know in Android, the roots of the garbage collector are: static variables and active threads. Case 1. We put applicationContext in the...
  • u

    user

    07/05/2022, 12:31 PM
    Kotlin, embed root_preferences in existing fragment Kotlin, I want to embed root_preferences.xml in a fragment with existing content. I navigate using I want to embed the preferences like this: // ... existing items // ... more items here What I did Create new Settings Fragment. This does NOT create a layout file, but an XML file at res/xml/root_preferences.xml, make no changes to code. Create a 'container fragment' new Fragment (Blank) name it, ContainerSettingsFragment. it creates the layout file fragment_container_settings. Delete code...
  • u

    user

    07/05/2022, 12:31 PM
    Feature query on Mapbox returns nothing sometimes Initializing Mapbox: In onViewCreated() we set the style for our Mapbox map and also call mapboxMap.queryRenderedFeatures() where we pass a geometry-point. Description of problem: Sometimes (1 out of 4 times) the queryRenderedFeatures() returns an empty list even though we are sure that it should return a list with elements. Question: Why is this happening? My guess is that maybe the style is not fully loaded when we query. But, I also tried to delay the queryRenderedFeatures() and I still...
  • u

    user

    07/05/2022, 1:11 PM
    Error :org.gradle.api.GradleException: Compilation error. See log for more details I am using jetpack with navigation and I implemented dependency which was in google dev's website and I am getting error when I lunch the app please have a look and tell me what is wrong. my Gradle: plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' } android { compileSdk 32 defaultConfig { applicationId "com.example.g10" minSdk 23 targetSdk 32 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"...
  • u

    user

    07/05/2022, 1:31 PM
    Kotlin optional parameters in annotation class (Cache Control Directive for GraphQL) I am using GraphQL Kotlin to generate a GraphQL schema. I would like to implement Caching for a subgraph, according to the documentation for inheritMaxAge: If true, this field inherits the maxAge of its parent field instead of using the default maxAge. Do not provide maxAge if you provide...
  • u

    user

    07/05/2022, 1:31 PM
    Image chooser using ActivityResultContracts but using my own Uri? I'm new to android development in general so I apologize if the question doesn't make sense. I'm hosting a Fragment with an ImageView and two buttons, one to set the ImageView through taking a picture, one to set it by choosing from gallery. This is how I create the Uri, which is later used for setting the image: photoUri=FileProvider.getUriForFile( requireContext(),"com.ron44.myapp",File.createTempFile("temp",".jpg")) This works well for taking the picture with camera because it takes my...
  • u

    user

    07/05/2022, 1:31 PM
    Kotlin JNI - Unsatisfied link error when calling external function but not when loading library C++ method signature: JNIEXPORT void JNICALL Java_abc_de_fg_jni_ProxyControls_startProxy(JNIEnv *env, jobject obj); Loading the library doesn't cause any errors: package abc.de.fg.jni class ProxyControls { init { System.load("/Users/***/***/lib***.dylib") println("loaded library") } external fun startProxy() } But running the startProxy method throws the error: Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: 'void...
  • u

    user

    07/05/2022, 1:51 PM
    Retrofit Android POST request with Header, Body, Path and Query I need to do a Retrofit POST request by Android Kotlin code and the format is as: [End Url]/api/customers/1/venues/55/abcfiles/sasfordownload?licenseid=01234567890&ispreproduction=true Headers: authorization -> Bearer someToken Body: { "some_field" : {"55" : "29"}} -- Response: "Some String Value" POST request: @POST("customers/{customers}/venues/{venues}/abcfiles/sasfordownload") fun makeRequestForfileUrl( @HeaderMap token: Map, @Path("customers") customers: Int,...
  • u

    user

    07/05/2022, 2:31 PM
    where is the trigger point when using sequence in kotlin? I'm studying kotlin in official site. I understand that the sequence has two type operation(intermediate, terminal). And the intermediate operation is triggered when the terminal operation is called. What I want to know is that the trigger point when the terminal operation is called. I deep dive into the code but couldn't find the source code. Where is the trigger source code? public fun Sequence.toList(): List { return this.toMutableList().optimizeReadOnlyList() } public fun...
  • u

    user

    07/05/2022, 2:31 PM
    Test infinite kotlin coroutine I have a ViewModel. When it's visible on screen, it's started. When user leaves the screen, it stops. While the ViewModel is started, I want to execute some code every 5 seconds. The code looks somewhat like this: fun onStart() { interval = launch(injectedDispatcher) { while (true) { doSomething() delay(5000.milliseconds) } } } fun onStop() { interval.cancel() } I want to write an integration test that will test this ViewModel along with...
  • u

    user

    07/05/2022, 2:31 PM
    Accessibility traversal order ignored I have created a custom navigation line menu on Android TV that consists of a LinearLayoutCompat with AppCompatButtons that each represents an entry in the menu. The menu is built dynamically, in the code at runtime by inflating the AppCompatButtons and then manually insert them into the parent via addView(...). Then I set the right order for Talkback in the code: // after adding the views to the parent menuItemsViews.forEachIndexed { index, menuItemView -> if (index <...
  • u

    user

    07/05/2022, 2:31 PM
    Why kotlin.math functions does not have implementation of Long I have been working with kotlin for little over 2 years now. Looking over what I learned in these 2 years, I noticed that I have been using(num.toDouble()).toLong() for kotlin.math functions a bit too much. For example, Math.sqrt(num.toDouble()).toLong(). Two of my projects have extension function sumByLong() inside util created by team, because kotlin libs only have sumBy:Int and sumByDouble:Double and a lot of work in the project, uses Long. In short, Mathematical operations using Long is...
Powered by Linen
Title
u

user

07/05/2022, 2:31 PM
Why kotlin.math functions does not have implementation of Long I have been working with kotlin for little over 2 years now. Looking over what I learned in these 2 years, I noticed that I have been using(num.toDouble()).toLong() for kotlin.math functions a bit too much. For example, Math.sqrt(num.toDouble()).toLong(). Two of my projects have extension function sumByLong() inside util created by team, because kotlin libs only have sumBy:Int and sumByDouble:Double and a lot of work in the project, uses Long. In short, Mathematical operations using Long is...
View count: 3