I’m writing a Hangman app for android and I encounter some loading problems.
When my app starts, I generate a random word picked from a txt file. The problem is that this file is heavy: it has almost 360’000 words (4000 kB), therefore picking a single word takes between 10 and 20 secs time, I know that it is because I read the file and pick a word each time I click on Generate.
Would it be a good thing if I read the file once the app starts and put its contents into a String Array? I don’t really know if an array can handle this much.
Otherwise what would be the good pattern?
Thanks for reading.
Execute the code to parse/load content form json/db in a AsyncTask for more speed. I load 5000 rows with ~ 400 chars per row. It takes without AsyncTask much longer.
To execute you just have to call:
Here you can learn more about AsyncTasks:
AsyncTask developer Guide