https://kotlinlang.org logo
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
android
  • n

    Nikola Milovic

    05/05/2020, 2:40 PM
    Doesn't seem that I'll get much traction on SO alone, might as well try my luck here... https://stackoverflow.com/questions/61521508/how-to-properly-change-access-in-parts-of-my-kotlin-android-library-so-that-the
    j
    • 2
    • 1
  • r

    robstoll

    05/05/2020, 6:29 PM
    Hi, I am totally new to android. Is there a tool which enables to check if a dex file is compatible with a certain API level?
    c
    e
    • 3
    • 33
  • d

    David Winer [G]

    05/05/2020, 10:11 PM
    Hi all, does anyone have any data you can share on the size impact of converting JVM/Android libraries from Java to Kotlin? Working with a library team that is looking for good benchmarks on this.
    c
    • 2
    • 1
  • z

    Zac Sweers

    05/06/2020, 5:35 AM
    @ channel isn’t a thing in slack. You also should not be trying to @ channel a channel with 26,000 members
    ➕ 3
    🤣 2
    c
    • 2
    • 1
  • a

    Apex

    05/06/2020, 7:31 AM
    How are the new swipe gestures in slack beta implemented ? If anyone could point to relevant documentation or example , it would be really great
    🤔 1
    s
    a
    z
    • 4
    • 5
  • n

    Nikola Milovic

    05/06/2020, 5:56 PM
    Any way to debug release build via attaching debugger? My app works in debug build but doesn't work in release (without changing the code). I can't pinpoint the problem as there are no errors. I just need to add breaks in release build somehow
    a
    k
    • 3
    • 2
  • i

    iex

    05/06/2020, 8:19 PM
    Hi! Please help with mocking in Unit Tests... I've a global logger class (I know this isn't ideal, but for now it's convenient) that wraps the Android logger. I'm now running unit tests and it crashes with "Method i in android.util.Log not mocked". So I need to mock this class somehow. Can I do that, given that it's in a global
    val
    ?
    t
    • 2
    • 4
  • m

    Marcin Wisniowski

    05/07/2020, 5:04 PM
    Hello, I'm trying to build a single activity app with the navigation library. My fragments load some data from the network in their `ViewModel`s. I want to show a loading screen when data is loading, without creating a loading screen in every fragment, so I want to have a loading screen layout in the main activity layout. But how do I communicate the loading state to the Activity? If the loading screen was in the Fragment, I could just have a
    LiveData
    with the loading state and toggle the loading screen based on that. But if the loading screen is in the Activity, I have no access to the Fragment's
    ViewModel
    . What am I missing?
    f
    r
    • 3
    • 6
  • v

    Vishvendu

    05/07/2020, 5:37 PM
    https://stackoverflow.com/questions/61660857/pass-data-from-fragment-with-recyclerview-to-the-other-fragment-using-viewmodel
    j
    • 2
    • 3
  • n

    Nikola Milovic

    05/07/2020, 5:42 PM
    Anyone had weird experiences with minifyEnabled shrinkResources My release build doesn't work (room database problems) when minify and shrink are enabled, but works when they are disabled. I've never noticed this for a long time, baffles me how can this affect the apps work. Edit: By not work i literally mean unusable app. I save some data into the database and then need it for later use, the data is null if the minify and shrink are enabled in release build, and it works fine if they're false. I seriously don't know what's happening The app is relatively small, should i just disable them all together?
    a
    r
    a
    • 4
    • 7
  • l

    lawlorslaw

    05/07/2020, 8:05 PM
    How do you write a junit test for this function? The part that fails is the call to
    file.sink()
    because it throws a
    FileNotFoundException
    .
    Untitled
    • 1
    • 1
  • a

    adams2

    05/07/2020, 11:01 PM
    Hey so I am trying to use the
    androidx.lifecycle.observe
    ktx extension. When I do
    viewModel.observe(this, ::myOnChanged)
    , I get this error:
    Type mismatch: inferred type is KFunction1<Action, Unit?> but Observer<in Action!> was expected
    . However, when I do
    viewModel.observe(this) { myOnChanged(it) }
    , the extension functions as expected. Is there some precedence rule preventing me from using a method reference?
    a
    k
    t
    • 4
    • 5
  • l

    lawlorslaw

    05/08/2020, 4:22 AM
    How do you wait for the results from N asynchronous operations?
    s
    • 2
    • 3
  • j

    Joao Birk

    05/08/2020, 4:28 PM
    Hi there, did anyone use this guy before? https://github.com/android/architecture-components-samples/blob/master/NavigationAdvancedSample/app/src/main/java/com/example/android/navigationadvancedsample/NavigationExtensions.kt Im trying to use it with a custom toolbar per fragment, the back button is not showing up. Did anyone use this with custom toolbar in their fragments successfully?
    m
    • 2
    • 22
  • p

    PenguinDan

    05/08/2020, 7:13 PM
    Hello, I am currently using Splitties View DSL https://github.com/LouisCAD/Splitties/tree/master/modules/views-dsl and I came across the following issue. • Attempting to start an AlertDialog with a custom size. I can't customize the size of the root layout (since we don't use a parent ViewGroup, aware of how LayoutInflater + Parent + attach to parent works)
    override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
        ): View? = EnsureDialogUi(requireContext()).apply {
            yesButton.setOnClickListener {
                ensureListener?.onYes()
                dismissSafely()
            }
    
            noButton.setOnClickListener {
                cancelSafely()
            }
        }.root
    
    // My Ui code
    ...
        override val root: View = constraintLayout {
            // Set the parameters of our ConstraintLayout container
            layoutParams = ConstraintLayout.LayoutParams(
                DeviceUtil.calcDiagRatioInt(0.33f), wrapContent
            )
    ...
    Any ideas how I would go about doing this?
    d
    l
    • 3
    • 6
  • d

    dewildte

    05/09/2020, 12:54 AM
    It seems to be corrupt on windows.
    v
    m
    • 3
    • 3
  • j

    Joshua

    05/09/2020, 1:59 PM
    I managed to setup my actionbar in my activity and it works fine. But since I'm using single activity pattern, I somehow want to access the actionbar from the fragment and make some adjustments there. Do I have to make this setup all the time? :
    val navController = findNavController(R.id.nav_host_fragment)
    val appBarConfiguration = AppBarConfiguration(navController.graph)
    findViewById<androidx.appcompat.widget.Toolbar>(R.id.toolbar).setupWithNavController(navController,appBarConfiguration)
    
    setSupportActionBar(findViewById(R.id.toolbar))
    This code is from my activity What I'm trying to do is, set this default back-arrow autogenerated button to a hamburger icon instead.
    i
    • 2
    • 4
  • s

    sathawale27

    05/10/2020, 1:44 PM
    Hey, anyone has any idea about creating a tablet emulator without a built-in hardware camera feature. So, I could test the application for my workflow.
    l
    • 2
    • 12
  • k

    krtko

    05/11/2020, 1:54 AM
    I've migrate over to Gradle's new
    plugins
    system and for some reason the Android plugin needs me to add
    pluginManagement {
        repositories {
            gradlePluginPortal()
            jcenter()
            google()
        }
        resolutionStrategy {
            eachPlugin {
                if (requested.id.id.startsWith("com.android")) {
                    useModule("com.android.tools.build:gradle:${requested.version}")
                }
            }
        }
    }
    to my
    settings.gradle
    file
    a
    g
    i
    • 4
    • 10
  • j

    Joao Birk

    05/11/2020, 2:25 AM
    Hi, has anyone used
    ShortcutInfo.Builder
    with navigation components? It needs an intent, there is no pendingIntent method that I can pass to the Builder, so cant really use
    NavDeepLinkBuilder.createPendingIntent().
    s
    i
    • 3
    • 8
  • l

    Leon johnson

    05/12/2020, 11:33 AM
    Hey guys thanks so much for accepting to this channel. Has anyone in here worked with fire base?
    :stackoverflow: 1
    g
    h
    • 3
    • 3
  • j

    jean

    05/12/2020, 2:32 PM
    I’m having some difficulties to understand how one can get an instance of a
    FlowCollector
    or anything build through the builder helpers function like
    flow { }, callbackFlow { }, etc...
    . What I want is to be able to do something like that from my fragment (or activity) but in a “correct” way
    private lateinit var collector: FlowCollector<MainFragmentEvent>
    
    private val events = flow<MainFragmentEvent> {
        collector = this
    }
    
    override onResume() {
        lifecycleScope.launch {
            collector.emit(MainFragmentEvent.ResumeEvent(requireContext()))
        }
    }
    Can I do that only by using
    Channel, SendChannel, etc...
    and then convert it some how to a
    Flow
    ?
    z
    n
    • 3
    • 3
  • r

    Remon Shehata

    05/12/2020, 4:37 PM
    //build the geofence
            val fence = Geofence.Builder()
                .setRequestId("123")
                .setCircularRegion(latitude, longitude, radiusInMeters)
                .setExpirationDuration(Geofence.NEVER_EXPIRE)
                .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
                .build()
    
            geofencingRequest = GeofencingRequest.Builder().apply {
                setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER)
                addGeofence(fence)
            }.build()
    
    
            //build pending intent
            val geofencePendingIntent: PendingIntent by lazy {
                val intent = Intent(activity, GeofenceReceiver::class.java)
                PendingIntent.getBroadcast(activity, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
            }
    
            //request
            geofencingClient.addGeofences(geofencingRequest, geofencePendingIntent).run {
                addOnFailureListener {
                    // display error
                }
                addOnSuccessListener {
                    // move on
                }
            }
    l
    • 2
    • 1
  • r

    Remon Shehata

    05/12/2020, 9:55 PM
    Hello guys, Have anyone used geofencing? I am trying to use it and I am stuck..
    n
    c
    • 3
    • 15
  • s

    Somesh

    05/13/2020, 6:48 AM
    Hello Guys, Does anyone of you have any idea why all of a sudden I started getting these errors when emitting FAILURE of Resource class which is a sealed class. it says "not enough information to infer type variable T" ? It wasn't there before. Compilation works normal. No crash. No error.
    w
    • 2
    • 3
  • l

    Leon johnson

    05/13/2020, 7:48 PM
    Hey guys I really need help please I am using Kotlin to create an Android App. The problem I am having is I’m trying to use a ViewModel to create an user in Firebase. After the user is created, something should be returned to the UI Fragment to let the fragment know to move forward to the next line of execution. The trouble I’m having is Firebase operations are done asynchronously, so there’s no way for the front end to know the operation is done executing in the view model. Is there a way to create a callback or fix this?
    b
    s
    p
    • 4
    • 8
  • g

    Gaurav K Tyagi 1

    05/14/2020, 7:49 AM
    Hi guys, I have a doubt Can kotlin coroutine completely replace rxJava?
    w
    • 2
    • 2
  • a

    antoniomarin

    05/14/2020, 8:37 AM
    Hello all, I’ve got one weird issue with
    ViewPager2
    and I cannot make any sense of it, I’ve got separate
    Activity
    that holds
    ViewPager2
    which contains fragments. That means destroying that activity with
    finish()
    closes
    ViewPager2
    as well. Now what I’ve got is beyond me, everything works fine when I start it for the first time, but if I close it and reopen my observables in the fragments won’t emit any changes, tho everything is created fine?. I’ve pinpointed issue to the
    createFragment
    method where commented part works but non commented doesn’t?
    class PagerAdapter( 
        fragmentActivity: FragmentActivity,
        private val items: List<PagerAdapterFragment>
        //private val items: List<Int>
    ) : FragmentStateAdapter(fragmentActivity) {
    
        override fun createFragment(position: Int): Fragment {
            return items[position].fragment
    //        return when (position) {
    //            0 -> Fragment1.newInstance()
    //            1 -> Fragment2.newInstance()
    //            2 ->  PlaceholderFragment.newInstance("Retention information screen")
    //            else ->  PlaceholderFragment.newInstance("Else")
    //        }
        }
    
        data class PagerAdapterFragment(val id: Long, val fragment: Fragment)
    i
    • 2
    • 4
  • l

    louiscad

    05/14/2020, 7:39 PM
    @jw I've seen you often advocate for usage of
    stdlib-jdk8
    in Android, but @mbonnin research came to the conclusion that
    stdlib
    (not
    stdlib-jdk7
    ) is often the best. I think I disagree since
    Autocloseable.use { ... }
    is quite useful for some Android APIs exposing it, and is part of
    stdlib-jdk7
    , but I've yet to see content
    stdlib-jdk8
    being used in actual Android apps, and it seems the best it has to offer is not used by Android apps because of ineffective way to determine runtime capabilities as ART isn't technically a JRE-8. If you can confirm what this article says, who can/should make the
    stdlib-jdk8
    content work on Android as it should? The D8/R8 team? The Kotlin team? The platform team, meaning only Android several years from now will get it? https://medium.com/@mbonnin/the-different-kotlin-stdlibs-explained-83d7c6bf293
    m
    • 2
    • 3
  • r

    Remon Shehata

    05/15/2020, 1:25 AM
    override fun checkOrganization(organizationId: String): Boolean {
        var isFound = false
        db.collection(FirebaseConstants.ORGANIZATION)
            .get()
            .addOnSuccessListener { querySnapshot ->
                for (document in querySnapshot) {
                    Log.d(TAG, document.id)
                    if (organizationId == document.id) {
                        isFound = true
                        
                    }
                }
            }
            .addOnFailureListener { exception ->
                Log.w(TAG, "Error getting documents.", exception)
            }
    
        return isFound
    }
    I want to return from the method after the loop is completed. how to achieve that?
    :stackoverflow: 2
    o
    • 2
    • 2
Powered by Linen
Title
r

Remon Shehata

05/15/2020, 1:25 AM
override fun checkOrganization(organizationId: String): Boolean {
    var isFound = false
    db.collection(FirebaseConstants.ORGANIZATION)
        .get()
        .addOnSuccessListener { querySnapshot ->
            for (document in querySnapshot) {
                Log.d(TAG, document.id)
                if (organizationId == document.id) {
                    isFound = true
                    
                }
            }
        }
        .addOnFailureListener { exception ->
            Log.w(TAG, "Error getting documents.", exception)
        }

    return isFound
}
I want to return from the method after the loop is completed. how to achieve that?
:stackoverflow: 2
o

OG

05/17/2020, 7:56 PM
Idk how this whole thing is used but what comes to mind is either passing in a callback interface to this class that is overriding
checkOrganization
and invoking the callback in the
addOnSuccessListener
. Another alternative would be changing this interface (if it's internal) and using coroutines so you can return the result asynchronously.
So a.) Use coroutines and mark
checkOrganization
a suspend function so you can return the result asynchronously. b.) Use traditional callbacks to pass the result at a later time (the end of the for loop in
addOnSuccessListener
View count: 1