Skip to content

fix: internalize image off the main thread#21392

Open
Phoenix1808 wants to merge 1 commit into
ankidroid:mainfrom
Phoenix1808:fix/multimedia_image_off_main_thread
Open

fix: internalize image off the main thread#21392
Phoenix1808 wants to merge 1 commit into
ankidroid:mainfrom
Phoenix1808:fix/multimedia_image_off_main_thread

Conversation

@Phoenix1808

Copy link
Copy Markdown
Contributor

When importing a selected image, internalizeUri() ran on the main thread: a ContentResolver query for the file name and a full file copy. For a large image or a slow document provider this can block the UI.

Make internalizeUri() a suspend function and move the two blocking calls to Dispatchers.IO, keeping the UI work on the main thread. The callers now invoke it from viewLifecycleOwner.lifecycleScope.

Issue: #21275

Purpose / Description

Describe the problem or feature and motivation

Fixes

  • Fixes #

Approach

How does this change address the problem?

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration (SDK version(s), emulator or physical, etc)

Learning (optional, can help others)

Describe the research stage

Links to blog posts, patterns, libraries or addons used to solve this problem

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

When importing a selected image, internalizeUri() ran on the main
thread: a ContentResolver query for the file name and a full file
copy. For a large image or a slow document provider this can block
the UI.

Make internalizeUri() a suspend function and move the two blocking
calls to Dispatchers.IO, keeping the UI work on the main thread. The
callers now invoke it from viewLifecycleOwner.lifecycleScope.

Issue: ankidroid#21275
@welcome

welcome Bot commented Jul 23, 2026

Copy link
Copy Markdown

First PR! 🚀 We sincerely appreciate that you have taken the time to propose a change to AnkiDroid! Please have patience with us as we are all volunteers - we will get to this as soon as possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant