Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Android / Embedded files android

Author
Message
matty47
13
Years of Service
User Offline
Joined: 20th Nov 2007
Location:
Posted: 15th Apr 2021 04:28
I have created an app that reads several text files into arrays when it starts. The files are located in the media folder. I built an android apk and installed it on android phone. When I try to run the app it says it cannot find the text file. Do I have to embed the files some other way? Program runs fine on windows.
App game kit studio, tier one.
matty47
13
Years of Service
User Offline
Joined: 20th Nov 2007
Location:
Posted: 15th Apr 2021 06:07
Found the problem -Android is case sensitive so my file name 2words.txt in code failed because the file was actually named 2Words.txt. - Case matters.
Now my problem is the time taken to load the files. In all there are some 279000 lines to read from 15 different files and be inserted into different arrays - taking an inordinate amount of time. Is there any way to save the arrays in the programme to save loading the text files at application startup?
Loktofeit
AGK Developer
12
Years of Service
User Offline
Joined: 21st Jan 2009
Location: Sarasota, FL
Posted: 15th Apr 2021 15:30
Do you have more information on when or how this information is used? How much time is it taking to load the data? How are you reading the data? Have you tested loading the data from smaller-sized files?

Maybe stagger the loading based on when the data is used? Are you putting the data into memory to use all or search it all?

If the latter, maybe searching the files instead of memory might be a solution to your load problem, although searching overall would be slower.

More info is needed.
LynxJSA's web games/quizzes - LynxJSA's Android apps
AGK Resource Directory
"Stick to a single main loop (DO...LOOP) and loop through it every frame.
Do everything inside functions.
Use finite state machines to control your game.
Use lots and lots of source files.
Use virtual resolution instead of the default percentage system." - Digital Awakening
SFSW
18
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 15th Apr 2021 21:28 Edited at: 15th Apr 2021 21:29
Agree with Loktofeit, more information would be helpful. I can offer some basic suggestions though. First, if you're reading data line-by-line from text files, that is generally the slowest method. Especially if each word consumes an individual line. You can usually get a significant performance boost by reading fewer lines with more characters in them. So for example, 10 words in one line with a delimiter and using 'GetStringToken2()' can usually be loaded much faster than loading 10 separate lines with one word each (repeated many times over at least). You may need to establish limits for character lengths, but once set up, the performance benefit can increase more with the more words involved.

Another effective approach is to save your text files as memblock files. So basically, have another program that loads your text files into memblock(s) and then saves them out with 'CreateFileFromMemblock()'. Then when you load them in your game, use 'CreateMemblockFromFile()' and read the values from the memblock directly when needed. Using this approach can also use a lot less memory, which is very important on mobile platforms as massive arrays can take a huge hit on mobile device memory resources (frequently causing more crashes). It's a little more challenging to set things up this way since you need to define the character lengths of the strings you save, but if you run into memory limitation issues and/or loading performance, it can help a lot.

Searching, as Loktofeit mentioned would be another approach. It will just depend on what it is you are trying to do and how you need to achieve it.
matty47
13
Years of Service
User Offline
Joined: 20th Nov 2007
Location:
Posted: 16th Apr 2021 08:43
Thanks for the replies. I was loading the files into arrays one line(word) at a time. The load was taking no time on the windows pc however on the android phone it was taking several minutes. I have overcome the problem by hard coding the words in arrays within the program. Load time now minimal. Only downside is the length of the lines in the editor. Eg the 8 letter word array has some 47000 individual words. No I did not type them in. I created a text file with each word in quotes and separated by commas and then pasted them into the ide. The editor handled this reasonably well.
So for the time being this seems to have solved my problem Thanks again.
matty47
13
Years of Service
User Offline
Joined: 20th Nov 2007
Location:
Posted: 16th Apr 2021 10:31
Just an outline of what I have done. The program accepts a set of letters and then finds all anagrams of the letters. Currently I have limited the input to 8 letters but will probably expand this to 10 or 11 letters. For instance if you input 6 letters the program will return 6, 5, 4, 3 and 2 letter words that can be made from the letters. The search for 8 letters only takes a few seconds. Fairly happy with the result - just needs some cosmetic work now.
Loktofeit
AGK Developer
12
Years of Service
User Offline
Joined: 21st Jan 2009
Location: Sarasota, FL
Posted: 16th Apr 2021 18:25
"The program accepts a set of letters and then finds all anagrams of the letters."

Do want.

When you release that, share a link. Also, don't forget to submit it to the Showcase.
LynxJSA's web games/quizzes - LynxJSA's Android apps
AGK Resource Directory
"Stick to a single main loop (DO...LOOP) and loop through it every frame.
Do everything inside functions.
Use finite state machines to control your game.
Use lots and lots of source files.
Use virtual resolution instead of the default percentage system." - Digital Awakening

Login to post a reply

Server time is: 2021-05-16 06:40:42
Your offset time is: 2021-05-16 06:40:42