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

Currently loaded card reloads when screen changes orientation #921

Closed
hssm opened this issue Jul 28, 2015 · 9 comments
Closed

Currently loaded card reloads when screen changes orientation #921

hssm opened this issue Jul 28, 2015 · 9 comments

Comments

@hssm
Copy link
Member

hssm commented Jul 28, 2015

Originally reported on Google Code with ID 18

What steps will reproduce the problem?
1. Start Ankidroid on your phone and let it load up a new card.
2. Tip your phone over to have it change orientation.
3. The "Loading deck. Please wait..." dialog appears and there is a long delay until
the new 
card appears.

Since Android restarts the activity on a configuration change like this, it will also
trigger a 
reopen of the database and a reload of the card to show. This is unnecessarily slow
in my 
opinion. Saving the card and just reload the layout should be enough.

Reported by daniel.svard on 2009-10-05 06:48:34

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Fixing the bug regarding the problems to write on all the surface of the Whiteboard
when the orientation changes I have already fixed this bug too.

When Android detects a change in orientation, by default exectues onCreate again.
This behaviour it's not desirable because we only want to change the UI, not reopen
the deck and reload the cards. If onConfigurationChanged(Configuration newConfig is
overridden Android will execute this function instead of onCreate, when the
orientation changes, so it solves the problem.

Reported by edu.zasu on 2009-10-23 09:38:54

  • Status changed: Fixed

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Great :-)

Reported by nicolas.raoul on 2009-10-23 09:43:33

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

I had a different solution in place here locally to fix this problem, but this one might
be better. I will try it 
out and see if it also fixes the problem with the crash on screen orientation change
while a deck is loading 
after it has been chosen in the deck picker.

Reported by daniel.svard on 2009-10-23 10:18:30

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

I don't know if I completely understood how to provoke this crash you are talking
about but I tried it and I think it works just fine.

Let me know if something it is not working!

Reported by edu.zasu on 2009-10-23 10:33:06

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

This is how I made it crash before:
1. Pick a new deck in the deck picker screen.
2. Rotate the screen while the "Loading deck. Please wait..." progress dialog is displaying.

It was a problem with the thread that is loading the deck trying to write to Ankidroid.currentCard,
but 
since the activity got restarted on the configuration change, that reference was not
valid any more. 
From reading the documentation on onConfigurationChanged, it seems that it prevents
the activity from 
being restarted and thus this problem would be solved too.

My solution involved using the onRetainNonConfigurationInstance() and getLastNonConfigurationInstance()
methods, as well as keeping a reference to the currently active 
activity and using a lock to limit the thread's access to it. 

Reported by daniel.svard on 2009-10-23 10:47:30

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

I didn't manage to reproduce this :-/
I have the country-capitals deck and a ~15000 cards deck, maybe they load too fast?
Both take less than a second to load.
I am using my master branch.

Reported by nicolas.raoul on 2009-10-23 10:54:44

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Then you probably fixed it too. :-D Don't worry.
I just pulled Nicolas' master branch and I'll try it out. 

I think it was present at this commit at least: bec770b0e1b04831b538b044deb116451023a76d
(in Nicolas' 
branch)


Reported by daniel.svard on 2009-10-23 11:05:49

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Thanks, Daniel! We'll be waiting your feedback on that ;D

Reported by edu.zasu on 2009-10-23 11:11:59

@hssm
Copy link
Member Author

hssm commented Jul 28, 2015

Tried it now and the bug doesn't seem to exist anymore. It also feels a lot more responsive
than my 
solution.
Great job Edu, thanks!

I'm thinking we should do something similar to the DeckPicker activity to not make
it reload all the deck 
data on an orientation change.

Reported by daniel.svard on 2009-10-23 11:21:52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant