Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

put disk access into background thread? - #12

Open
yulin2 wants to merge 9 commits into
brk3:masterfrom
yulin2:master
Open

put disk access into background thread?#12
yulin2 wants to merge 9 commits into
brk3:masterfrom
yulin2:master

Conversation

@yulin2

@yulin2 yulin2 commented Oct 19, 2014

Copy link
Copy Markdown

Hi, I'm doing research on performance for Android apps. I found some event handlers access disk (read/write files, decode bitmap) from UI thread, but Android docs suggest us to avoid such blocking calls in UI thread. Do they lead to any responsiveness issues?

I tried to refactoring by putting them into background tasks. Looking forward to see your comments.

put json loading into background thread.
put picture save into background thread.
put bitmap decoding into background thread.
put bitmap decoding into background.
@yulin2

yulin2 commented Oct 30, 2014

Copy link
Copy Markdown
Author

I sent this pr several days ago. Any idea/comments?

@brk3

brk3 commented Dec 2, 2014

Copy link
Copy Markdown
Owner

@yulin2 Sorry for the delay, Github didn't seem to notify me for some reason so never noticed your PR! Looks ok so far, have you noticed any performance increases from this? I'll do some tests this evening.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing import for Bitmap

@yulin2

yulin2 commented Dec 3, 2014

Copy link
Copy Markdown
Author

Thanks for the reply. I didn't measure performance increase from these refactorings. I apply them based Android docs' suggestion: blocking I/O calls (db, disk, bitmap decode) should be in background thread.

I manually tested the changes but didn't get that exception before. That exception is due to data races on "mPhotos" field. onPageSelected is executed before the initialization in onPostExecute. I remove the changes in PhotoViewerActivity.java to avoid such races.

Sorry for the missing import and final keyword. It's because I typed and committed via the Github web interface so I miss them. Now I added them. I may also create a cleaner pr if you think the changes are ok.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants