Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race Condition when loading media and changing the view size #13

Closed
pavol-bielik opened this issue Apr 18, 2014 · 2 comments
Closed

Race Condition when loading media and changing the view size #13

pavol-bielik opened this issue Apr 18, 2014 · 2 comments

Comments

@pavol-bielik
Copy link

Description

It is possible to change the view size of media while they are loading in the background.
As a result the medias can be temporary shown in the wrong order.

Steps to reproduce the issue

Initial state: main activity showing the listing of medias by folder is shown and view size is set to medium
Initial

  1. click on option at top of the screen and change the group by to Date. As a result a background task is created that first loads the medias and sorts them based on the selected grouping.
  2. while the medias are loading, change the view size to small. The application takes currently shown medias and immediately redraws them with the new view size. However, it already accounts for the changed grouping option and takes the old medias (ordered by folder) and groups them by date. As a result they are very likely to be in the wrong order.
    Loading
  3. The background task created in step 1. finishes and redraws the medias in the correct order.
    Final

The wrong execution can be easily triggered after adding Thread.sleep to simulate slow database before Utils.loadMedia(false) call.

Possible Fix

We can make the two events (changing the view size and loading) commutative by always resorting the current medias when the view size changes.

@rafali
Copy link
Owner

rafali commented Apr 18, 2014

Thanks for the detailed bug report. I'll fix it.

@rafali
Copy link
Owner

rafali commented Apr 28, 2014

Solved using @Background(serial = "load")

@rafali rafali closed this as completed Apr 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants