Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭 适合新手
#439 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 7 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1 小时以内
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
android, kotlin
领域
mobile

调研方向

该调用位于 app/src/main/kotlin/org/fossify/clock/activities/MainActivity.kt 中的 checkShortcuts(),由 onResume() 调用,大约在第 133 行。阅读同一 Activity 中现有的 ensureBackgroundThread { ... } 代码块是如何使用的,然后只把 shortcutManager.dynamicShortcuts = ... 赋值移到后台调度器上。完成标准是:该赋值不再在主线程上运行,快捷方式列表保持不变,并且应用仍能正常构建。

由索引模型根据 Issue 内容生成。

描述

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)

主要语言
Kotlin
星标
706
派生
73
平均合并
5 天 17 小时
30 天内合并 PR
8

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

FossifyOrg/Clock 的其他 Issue

查看 FossifyOrg/Clock 的全部 Issue

相似的 Issue

更多 Kotlin Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。