https://kotlinlang.org logo
Join SlackCommunities
Powered by
# stackoverflow
  • r

    rss

    05/09/2025, 11:41 PM
    Jetpack Compose navigation between screens using bottom navigation bar and buttons within the screens I have the following basic code in Android, Jetpack Compose: import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment...
  • r

    rss

    05/10/2025, 11:01 AM
    How to fix memory leak from Pager.flow.cachedIn LeakCanary's logs show that after ViewModel.onClear() the pageModelPagingDataFlow does not release memory. @HiltViewModel class DocPageListViewModel @Inject constructor( private val docPageDao: DocPageDao, ) : BaseViewModel() { val pageModelPagingDataFlow = Pager(PagingConfig(pageSize = 10, initialLoadSize = 20)) { docPageDao.getPagingSource() }.flow.cachedIn(viewModelScope) } @Dao interface DocPageDao { @Query(""" SELECT rowid, lid,
    key
    FROM...
  • r

    rss

    05/10/2025, 8:21 PM
    ROOM Database Query syntax. Query runs correctly directly in Database Inspector but not in ROOM DAO query I want to add a variable WHERE parameter to my DAO query but it is not working as I expect. @Query("SELECT * FROM item WHERE category isnull and subroomId= :subroomId and :filter ORDER BY category, itemtype, itemname ASC") fun getitems(subroomId: Long, filter:String = "(1 = 1)": Flow The [:filter] parameter will allow to me to add in the program more complex expressions, for example (itemname like 'test'), and other much more complex expressions, without having to rewrite the DAO query. The...
  • r

    rss

    05/10/2025, 11:01 PM
    how do I resolve this Ensure viewModel() works by relying on the lifecycle-viewmodel-compose dependency build.gradle.kts (Module: app) plugins { id("com.android.application") id("org.jetbrains.kotlin.android") } android { namespace = "com.oneorangetree.homequestbyshayaan" compileSdk = 34 defaultConfig { applicationId = "com.oneorangetree.homequestbyshayaan" minSdk = 34 targetSdk = 34 versionCode = 1 versionName = "1.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" vectorDrawables {...
  • r

    rss

    05/11/2025, 2:21 AM
    bump kotlin multiplatform compose from 1.7.3 to 1.8.0 , build failed when I bump compose from 1.7.3 to 1.8.0 , the project build failed by Xcode and fleet. I dont know what happened.

    https://i.sstatic.net/Jfni7eR2.png▾

    ld: warning: ignoring duplicate libraries: '-lc++' ld: warning: object file...
  • r

    rss

    05/11/2025, 4:41 AM
    Resetting Expo/RN Environment I need to reset my expo/rn environment because it was working properly, but incidentally I used npx react-native doctor and then from then on, all my RN/Expo projects stop building. On a clean expo installation using npx create-expo-app@latest, if I were to do npx expo run:android and build, I get alot of buildCMakeDebug[arm64-v8a][reanimated,worklets] FAILED errors. I've tried Removing home ~/.gradle/cache android/gradlew clean all kind of answers online Remove Android Studio and...
  • r

    rss

    05/11/2025, 6:21 AM
    Problem regarding getting old UI in credential manager API in android I am trying to make login flow using google sign-in in android using credential manager but I always end up getting old traditional google sign-in UI. Here is my code for reference. import android.content.Intent; import android.os.Bundle; import android.os.CancellationSignal; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import...
  • r

    rss

    05/11/2025, 8:21 AM
    How to make Equalizer using Exoplayer and jetpack compose I want to create a Equalizer for my music application but i am not able to understand official Equalizer doc made by google developers . I want to know how can i implement this feature in jetpack compose . i need a sample working with bare minimum code I have tried to follow https://developer.android.com/reference/android/media/audiofx/Equalizer this doc but its not begineer friendly
  • r

    rss

    05/11/2025, 1:11 PM
    Android 14+: How to correct check and request boot auto start permission Project 1: https://github.com/XomaDev/MIUI-Autostart A library to check MIUI autostart permission state. Project 2: https://github.com/judemanutd/AutoStarter This library helps bring up the autostart permission manager of a phone to the user so they can add an app to autostart. Project 1 is only for checking the permission and...
  • r

    rss

    05/11/2025, 1:11 PM
    ExoPlayer zooms or crops video after quality change on Android TV using Media3 (v1.6.1) I'm working on a video streaming app that uses ExoPlayer with Media3 version 1.6.1 and androidx.media3.ui.PlayerView inside Jetpack Compose. Our service streams live and on-demand content (like Aparat Sport), and we allow users to manually change video quality using TrackSelectionOverride. The issue occurs only on some Android TVs (e.g. Xiaomi TV) and is very consistent: ✅ Problem: When I change the video quality (e.g. from 480p to 1080p), the video: Becomes cropped or zoomed in to the...
  • r

    rss

    05/11/2025, 1:31 PM
    AutofillService Memory leak reported by LeakCanary Im facing an issue when working with AutofillService in android. I have created a service that responds successfully to an autofill request from the Android OS, example from Firefox After a few seconds LeakCanary detects a memory leak. not sure what causes it I use coroutines in my service as shown below, i hold a weak reference to the service for context and release it when the coroutine finishes. Anyone experienced this issue or have some idea whats going on? private val serviceScope =...
  • r

    rss

    05/11/2025, 5:31 PM
    @Composable invocations can only happen from the context of a @Composable function PROBLEM? Can someone explain me this why text is doing this? I am new to android development. Please explain the proper reason with solution. @Composable fun Greeting(name: String, modifier: Modifier = Modifier) { LazyColumn { items(10) { i -> Text(text = "Hey HARSH") } } } I tried few videos on youtube but not get the result.Also give me some best resources to learn this jetpack compose.
  • r

    rss

    05/11/2025, 7:51 PM
    Jni call to create MaterialButton fails on Android Runnable, but works on UI thread I am trying to create a new MaterialButton when the user clicks on a MaterialButton using jni. The first MaterialButton is created on the UI thread without problem, but when I click or create a new MaterialButton inside an Android Runnable, then the app crashed with the following error: java.lang.ClassNotFoundException: Didn't find class "com.google.android.material.button.MaterialButton" on path: DexPathList[[dex file "InMemoryDexFile[cookie=[0,...
  • r

    rss

    05/11/2025, 10:51 PM
    How to update data in a RecyclerView using LiveData and a SearchView I have a Room database (with dao), a Repository, a ViewModel a RecyclerView and an Adapter interacting with each other. Right now the RecyclerView just displays all the item in my ReferenceItem table. I want to add a Search Bar at the top and filter the results in the RecyclerView. Here is how I implement my RecyclerView and its Adapter in the Fragment: @SuppressLint("NotifyDataSetChanged") override fun onViewCreated(view: View, savedInstanceState: Bundle?) {...
  • r

    rss

    05/11/2025, 11:51 PM
    WebSocket NS_ERROR_WEBSOCKET_CONNECTION_REFUSED I created a Project and before i implemented Spring Security (and other businesslogic too) the web socket worked fine. Now i get the following error when i try to use the echo web socket: NS_ERROR_WEBSOCKET_CONNECTION_REFUSED Status-Code: 405 I use Spring Security with the following filterChain: @Bean fun filterChain(http: HttpSecurity): SecurityFilterChain { http { csrf{ disable() } headers { disable() } authorizeHttpRequests {...
  • r

    rss

    05/12/2025, 1:31 AM
    NullPointerException on myTextView?.text = myString - Why isn't safe call working as expected? I'm encountering a NullPointerException in my Android Kotlin code on a line where I'm using a safe call operator (?.) which I expected to prevent this. Specifically, the line in question is: myTextView?.text = myString Where myTextView is a TextView and myString is a String. I expect that if myTextView is null, the right-hand side of the assignment would not be evaluated, and the line would be effectively skipped. However, I am still getting the following stack trace:...
  • r

    rss

    05/12/2025, 2:11 AM
    How to represent the changes to an instance of a data class (diff) in Kotlin? I maintain an application which helps users to track the progress of an activity in real time. In essence, we represent the state of said activity as a data class in the Android mobile app. Every time some aspect of the activity changes, either in the client or the server, the whole representation of the activity is sent as the body of an API request or response. What would be an effective way to instead only send and receive the aspects of the activity state (i.e., the properties of the...
  • r

    rss

    05/12/2025, 4:51 AM
    How to keep a persistent foreground notification alive even when the app is killed.(Flutter) I'm trying to implement a persistent live notification in my Android app using RemoteViews. It works fine while the app is in the foreground , but when the app is in background or swiped away (force-killed from recent apps), the notification also disappears. I want the notification to remain persistent (like a foreground service notification) even when the app is killed. @RequiresApi(Build.VERSION_CODES.O) class LiveNotificationManager(private val context: Context) { private val...
  • r

    rss

    05/12/2025, 4:51 AM
    Why is my Flutter overlay only playing sound but not visible on screen (using FlutterOverlayWindow)? I'm developing a Flutter app that displays breaking news using flutter_overlay_window. The overlay is supposed to show a red banner at the top or bottom with the news title and a close button. The sound plays correctly when the overlay is triggered, but the overlay window itself is not visible on the screen — it's completely transparent or not rendering. I'm using FlutterEngineCache to send a MethodChannel call from a background Android BroadcastReceiver (OverlayCloserReceiver) to close the...
  • r

    rss

    05/12/2025, 5:31 AM
    Compose Ripple adding transparency in app but not previews When trying to implement the new compose ripple configuration, I am running into this issue where my ripple on a preview shows up perfectly, but the ripple on the emulator in a built app is showing incorrectly

    video of compose preview▾

    class ComposeFragment: Fragment() { @OptIn(ExperimentalMaterial3Api::class) override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?,...
  • r

    rss

    05/12/2025, 7:51 AM
    Setting headers with the headers block is not working with Ktor HTTP Client I am using Ktor Client 3.1.3 in my Kotlin application. The HTTP Client is initialised like this: val httpClient = HttpClient { install(HttpCookies) install(ContentNegotiation) { json() } install(Logging) { logger = Logger.DEFAULT level = LogLevel.ALL } } I am trying to send a post request and set some of its headers. It works when I do this: val resp = httpClient.post(myUrl) { header(myHeaderKey, myHeaderValue) setBody(myBody) } But it...
  • r

    rss

    05/12/2025, 8:31 AM
    TorchScript error: "The size of tensor a (3549) must match the size of tensor b (8400)" using YOLOv8 model on Android with PyTorch Mobile I'm developing an Android application that uses a YOLOv8 model exported to TorchScript, which I load with PyTorch Mobile for object detection. The model was exported using Ultralytics with the following command: # Cargar el modelo YOLOv8 preentrenado model = YOLO("yolov8n.pt") # Entrenar el modelo model.train(data=yaml_path, epochs=50, imgsz=416, batch=8, workers=0, verbose=False, device=device) # Guardar el modelo entrenado model_path = "yolov8_fruits_model.pt"...
  • r

    rss

    05/12/2025, 8:51 AM
    Is this a valid tech stack for my backend? (Kotlin, Ktor, Exposed, Google Cloud, Firebase Auth, Firebase App Check) [closed] I have an existing Android app which I'd like to enhance by implementing a custom backend which is composed of a relational database and user authentication based on Firebase Auth. The business domain model might be something like a recipe app with data such as the sample below. It is not set in stone and just serves as a placeholder for my domain. { "name": "Cheesecake", "ingredients": [ { "name": "Banana", "amount": 150, "unit": "grams"...
  • r

    rss

    05/12/2025, 11:31 AM
    Why does Kotlin require open keyword to allow overriding? Doesn't this violate the open-closed principle? In Kotlin, classes and their members are final by default. To make a class extensible or a method overridable, you have to explicitly mark it with the open keyword. This design choice feels like it contradicts the open-closed principle (OCP) in object-oriented programming, which states that entities should be open for extension but closed for modification. In Kotlin, if I want to extend an existing class with new behavior, I often need to go back and modify the original class just to mark it...
  • r

    rss

    05/12/2025, 1:11 PM
    Google Drive Automatic Syncing across devices (Kotlin app) Hello everyone — I'm building my first Android app with Kotlin, so bear with me! The app contains some files and some pictures and the user has the possibility to choose the google drive back up option. The drive option would allow the user to upload his/her files/pictures on an app-specific drive folder and then if a change is made to update the corresponding file, if a deletion is made to delete the corresponding file etc. So far, I have implemented that. The issue however comes in when the...
  • r

    rss

    05/12/2025, 3:31 PM
    Gradle stdout cursor control I am working on a Gradle plugin, where I download some files from remote API in parallel. I want to inform user about the progress of each file. Let's say there are 10 files that are being downloaded, I'd like to print the current download/parse status, one line per file, dynamically, eg. "File1.txt: Downloading…", which would later change to "File1.txt: Parsing…", etc. I worked out that I can utilize some control sequences to set the cursor position and basically overwrite the text that was...
  • r

    rss

    05/12/2025, 4:11 PM
    Kotlin 2.0.0 Compatibility with KSP and Hilt – Version Mismatch Issues I'm currently updating my Android project to use Kotlin 2.0.0, but I'm running into compatibility issues with KSP and Hilt. In Kotlin 1.9.23, everything worked smoothly, but with the latest Kotlin version, I can't find stable versions of KSP and Hilt that are fully compatible with each other and Kotlin 2.0.0. Issues I'm facing: KSP version mismatches or crashes at build time. Hilt (especially hilt-compiler) seems to throw errors or fails to generate necessary code. Downgrading back to Kotlin...
  • r

    rss

    05/12/2025, 5:31 PM
    How to upload mapping file of an Android obfuscated library to Crashlytics We have an Android library that we obfuscate, we then have an application (un-obfuscated) that implements the library, which has Firebase Crashlytics implemented, is it possible to use the mapping file for de-obfuscated logs of the library? I know that it does not seem to be possible to add Crashlytics to the library itself. What are my options? Any help would be appreciated.
  • r

    rss

    05/12/2025, 6:51 PM
    Hibernate 6 - Can not invoke "Object.getClass()" because "value" is null I had issue after moving to Hibernate 6.7 following update criteria query snippet was causing an exception in new SQM model. criteriaQuery.set(root.get(MyEntity_.tag), null as Tag?) was throwing an exception: Can not invoke "Object.getClass()" because "value" is null
  • r

    rss

    05/12/2025, 7:31 PM
    PointerEvent shows position 1.333 times from the actual touch point on samsung devices Apologies for the size of the sample, I have tried to minimize it, but when I took to much away, it wasn't working. My problem is in the section if( distance( ptr.pos, it.position) > 10f ) { Log.d("Demo", "${ptr.pos} => ${it.position}") ShowRatio( ptr.pos, it.position) } Recently on some Samsung Galaxy TAB S7 devices, I have seen strange behavior where the positions I have been getting for the second and subsequent PointerEvents are scaled by a factor of 4/3 (the...