Skip to content

Synchronous Bitmap decoding in onActivityResult of AccountInfoPresenceActivity.java blocks the UI thread #245

@nbd-boss

Description

@nbd-boss

Description
Inside onActivityResult(), the following code synchronously calls
AppImageUtil.scaledBitmapFromContentUri(...):

Bitmap bmp = AppImageUtil.scaledBitmapFromContentUri(
        this, resultUri, AVATAR_PREFERRED_SIZE, AVATAR_PREFERRED_SIZE);

Since onActivityResult() runs on the main (UI) thread, and
scaledBitmapFromContentUri() internally performs:

  • ContentResolver.openInputStream() (disk / IPC I/O)
  • BitmapFactory.decodeStream() (CPU-intensive and memory-heavy, called twice)

this can block the UI thread, especially when handling large images or on low-end devices.

Impact

  • UI thread blocking
  • Noticeable frame drops or "jank" after the user crops an image
  • Potential ANR in worst cases

Suggested Fix

  • Move bitmap decoding to a background thread (e.g. Executor, Coroutine, RxJava)
  • Post the result back to the UI thread to update the ImageView

Additional Notes

  • The Android official documentation strongly recommends avoiding I/O operations and other long-running tasks on the main thread to prevent ANRs.

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