Skip to content

UI thread may be blocked in onResume due to synchronous setLayerType execution #521

@nbd-boss

Description

@nbd-boss

Description

During code analysis, we noticed that when LocationActivity.onResume() is invoked, the application may experience noticeable UI jank or temporary freezing under certain conditions.

The issue appears to be caused by a synchronous call to LocationView.setLayerType() on the main (UI) thread.
When a data-intensive layer (e.g., NEXRAD) is selected, this method may perform blocking file I/O and bitmap/data parsing, delaying UI rendering until the operation completes.

It may increase the risk of ANR in extreme cases.


Root Cause Analysis

  • LocationActivity.onResume() directly invokes LocationView.setLayerType(...)

  • setLayerType() triggers layer-specific parse() logic

  • The parsing process (e.g., in BitmapHolder constructors) involves:

    • synchronous file I/O
    • bitmap decoding and memory allocation
  • These operations run on the UI thread, blocking rendering and user interaction


Suggested Improvement

It is recommended to move the time-consuming operations inside setLayerType() (file I/O, data parsing, bitmap decoding) off the UI thread and execute them asynchronously.

One possible approach:

  1. Trigger a background task when resuming the activity or when the user changes the layer
    (e.g., using Kotlin coroutines, RxJava, or an Executor)
  2. Perform file reading and data/bitmap parsing in the background
  3. Switch back to the UI thread after completion to update the view with the prepared data

This change would improve UI responsiveness and reduce the risk of jank or ANR during lifecycle transitions.


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions