Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#439 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 7 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
8

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

FossifyOrg/Clock のほかの issue

FossifyOrg/Clock の issue をすべて見る

似ている issue

Kotlin の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。