Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

`setDynamicShortcuts()` is called from the Activity main thread

Abierto Apto para principiantes
#439 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 7 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
Menos de una hora
Aptitud para principiantes
74/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
android, kotlin
Área
mobile

Línea de trabajo

La llamada está en checkShortcuts() en app/src/main/kotlin/org/fossify/clock/activities/MainActivity.kt, a la que se llega desde onResume(), alrededor de la línea 133. Lee cómo se usa el bloque existente ensureBackgroundThread { ... } en la misma Activity y luego mueve solo la asignación shortcutManager.dynamicShortcuts = ... a un dispatcher en segundo plano. Está terminado cuando la asignación ya no se ejecuta en el hilo principal, la lista de atajos no cambia y la app sigue compilando.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug needs triage

Hi, I'm working on a research prototype static analyzer targeting Kotlin-based Android apps, and running it against this repo. It detected a small threading issue.

Checklist
  • I can reproduce the bug with the latest version given here.
  • I made sure that there are no existing issues - open or closed - to which I could contribute my information.
  • I made sure that there are no existing discussions - open or closed - to which I could contribute my information.
  • I have read the FAQs inside the app (Menu -> About -> FAQs) and my problem isn't listed.
  • I have taken the time to fill in all the required details. I understand that the bug report will be dismissed otherwise.
  • This issue contains only one bug.
  • I have read and understood the contribution guidelines.
Affected app version

Trunk

Checked file:

app/src/main/kotlin/org/fossify/clock/activities/MainActivity.kt

What I found

In MainActivity, onResume() calls checkShortcuts(). Inside checkShortcuts(), the stopwatch shortcut is published like this:

shortcutManager.dynamicShortcuts = listOf(stopWatchShortcutInfo)

This property setter calls ShortcutManager.setDynamicShortcuts(...). Android's API documentation warns that this method may take several seconds to complete and should only be called from a worker thread.

Verified bug trace

org.fossify.clock.activities.MainActivity.onResume()
  -> checkShortcuts()
  -> MainActivity.kt, around line 133:
       shortcutManager.dynamicShortcuts = listOf(stopWatchShortcutInfo)
  -> Kotlin property setter calls:
       ShortcutManager.setDynamicShortcuts(List<ShortcutInfo>)
  -> platform shortcut state is updated through ShortcutManager
  -> documented as potentially taking several seconds
  -> call is reached from the Activity main-thread lifecycle path
  -> possible UI stall / delayed startup / ANR risk

I did not see a worker-thread boundary around this specific shortcut publishing call. There is an ensureBackgroundThread { ... } used elsewhere in the same Activity for alarm rescheduling, but not around shortcutManager.dynamicShortcuts.

Why I think this is worth changing

This probably does not fail every time, and it may be fast on many devices. The problem is that the platform API is documented as potentially slow, and the work may depend on system/launcher behavior. If it takes longer than expected, it can block UI drawing and input handling.

Suggested change

Move just the publishing call to a worker thread:

val shortcuts = listOf(stopWatchShortcutInfo)

lifecycleScope.launch(Dispatchers.IO) {
    shortcutManager.dynamicShortcuts = shortcuts
}

This keeps the UI thread free while preserving the same shortcut behavior.

Reference

Android documents ShortcutManager#setDynamicShortcuts(...) as a potentially slow call:

This method may take several seconds to complete, so it should only be called from a worker thread.

https://developer.android.com/reference/android/content/pm/ShortcutManager#setDynamicShortcuts(java.util.List%3Candroid.content.pm.ShortcutInfo%3E)

Lenguaje dominante
Kotlin
Estrellas
706
Forks
73
Merge medio
5 d 17 h
PR fusionados (30 d)
8

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de FossifyOrg/Clock

Todos los issues de FossifyOrg/Clock

Issues similares

Más issues de Kotlin

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.