You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Confirmed — still present on current main. The freeze is not the file read (that already runs off the UI thread); it's rendering the whole file into a single TextView on the main thread.
In PreviewTextFragment.kt the TextLoadAsyncTask reads the entire file into one StringWriter/String with no size cap (doInBackground → String(result.buffer)), then on onPostExecute (UI thread) does textView.text = text. Measuring/laying out a multi-megabyte string in a single TextView (StaticLayout build) on the main thread is the ANR — a 2 MB file produces a 2 MB+ CharSequence for one view.
For .md files it's worse: the same full string goes through markwon.setMarkdown(textView, text) in PreviewFormatTextFragmentStateAdapter.PreviewFormatTextFragment — synchronous Markdown parsing of the whole document on the UI thread, again uncapped.
So the bug reproduces by design: background read OK, but the big-string layout/parse on the main thread blocks. A loading dialog now shows during the read, but it's dismissed right before the expensive UI-thread layout, so the freeze still surfaces.
Fix directions (any of):
Cap preview size (read first N bytes/lines, append a "truncated, open with…" notice).
Render incrementally / use a paginated or RecyclerView-backed view instead of one TextView.
Move Markdown parsing off the main thread (markwon.toMarkdown(text) on a worker, then setParsedMarkdown on the UI thread) and cap input.
Activity
michaelstingl commentedon Apr 13, 2023
Check if there are any libraries for this?
DeepDiver1975 commentedon Jun 29, 2026
Confirmed — still present on current
main. The freeze is not the file read (that already runs off the UI thread); it's rendering the whole file into a singleTextViewon the main thread.In
PreviewTextFragment.kttheTextLoadAsyncTaskreads the entire file into oneStringWriter/Stringwith no size cap (doInBackground→String(result.buffer)), then ononPostExecute(UI thread) doestextView.text = text. Measuring/laying out a multi-megabyte string in a singleTextView(StaticLayoutbuild) on the main thread is the ANR — a 2 MB file produces a 2 MB+CharSequencefor one view.For
.mdfiles it's worse: the same full string goes throughmarkwon.setMarkdown(textView, text)inPreviewFormatTextFragmentStateAdapter.PreviewFormatTextFragment— synchronous Markdown parsing of the whole document on the UI thread, again uncapped.So the bug reproduces by design: background read OK, but the big-string layout/parse on the main thread blocks. A loading dialog now shows during the read, but it's dismissed right before the expensive UI-thread layout, so the freeze still surfaces.
Fix directions (any of):
RecyclerView-backed view instead of oneTextView.markwon.toMarkdown(text)on a worker, thensetParsedMarkdownon the UI thread) and cap input.Files:
owncloudApp/src/main/java/com/owncloud/android/ui/preview/PreviewTextFragment.kt,.../PreviewFormatTextFragmentStateAdapter.kt.🤖 Generated with Claude Code