I'm working on an Android port of my game and I'm using the Android emulator with a Android 4.0.3 setup. My app is relatively large, because I've included 3 sets of graphics files, one for 320x480 (small) and 480x720 (normal) and one for 640x960 (highres).
What I've noticed is that when I install an APK file and start it for the first time, it takes a very long time to start. It only shows the top bar with batery and time, and a bar with the app name, the rest is black screen. Then after a short while, a dialog appears: "<app name> is not responding. Would you like to close it? wait/ok". I press wait a few times and finally give up and close the app. Then I reopen the app, and it usually seems that some (in some cases all) graphics files are missing.
When I go to Settings -> Apps -> App info, under Storage it displays this (also see attachment):
App 23MB
USB Storage app 0.00B
Data 17MB <-- !?
SD card 0.00B
The App and USB Storage seem normal but the Data part seems abnormally large. I suspect that the media files are copied from the APK file to some other location in Data and are used from there. Is this normal? Why is this? Can I change some settings in android to speed this up or prevent this copying from happening at all?
cheers,
Bas
[attachment deleted by admin]
I wonder that too and yes you are right, some media is copy.
If you look in the logfile, its copy and scanning in the Media Directory. I also wonder too why its does that and what its does?
I do prefer all media on the SDCARD and NOT on internal memory, because most phones does not have so much memory and games can been nicely played from the SD CARD. Games general can perfectly been using that. So its does not given any mean at all?
If Media is copy from the APK its a another story throught, which I guess its cant been avoid at all.
The best is, its would been nice if its could been happens after graphics have been init and eventuelly shown a splash screen from a contain file (example main.png or main2.png for a bigger version).
Looking into this a while ago yes, all the media files are copied from the apk so they can be used as normal when you first run your app.
Unfortunately this happens within the code that starts up the app, causing the OS to leave the screen blank while all the files are copied...
I didn't have enough knowledge to work out how to call the copy media function from within GLB or at least after the app had started - it would be easy to display a splash screen if someone can figure out a way to call the copy media function from within GLB...
If someone can get that working, then it would be possible to modify the java code to save the files somewhere on the SD card with your program simply loading the media files from there. For now you're stuck with the appearance of bloated data.
Okay I see, so the files cannot be used directly from the APK folder? Btw my PNG and WAV files are not compressed or shoeboxed or anything, but I assume this doesn't matter..
When this copying of files takes a little longer (like with my case ~17MB or on slow devices) then AndroidOS will prompt the user "app is not responding. Would you like to close it? wait/ok". And when the user pressed OK to close the app this also stops the copying of files, even when it is only halfway completed.
Unfortunately, the next time the app is started the copying is not resumed or completed. Also, when the user goes to settings and app info, and presses the "clear data" button then all media files are gone. Is there a way to recover from this situation, and force the media files to be copied again?
Hm. See what I do in the Java file. Can anyone assist?
Looking at the SDLActivity.java file, the function "copyAssets" seems to copy/overwrite the entire Media folder if it doesn't exists yet, or if the folder date is older than the APK file.
However, ideally it should check the modified date (or filesize) of each individual file and not just the folder, and copy each file if needed. That way, it will resume copying files when the app is started a second time after it was previously halted during the copyAssets.
Unfortunately, I don't have good java skills so.. sorry, but I wouldn't know how to do this. :doubt:
(btw why is this copy needed at all?)
its possible to get the source folder from SDLActivity.java by doing this under protected void onCreate(Bundle savedInstanceState), and then use "TEMP" in PLATFORMDIR$ to get that dir:
SetFilesPath(dataDir.toString(),
AndroidId.toString(),
this.getApplicationInfo().sourceDir.toString(),
java.util.Locale.getDefault().getLanguage(), // getDisplayCountry()
keyboardPresent,
ext_storage);
howover its returning a pkg.apk file, which I guess its contain all its assests (but not SO files, its have own dir). But if we could do a SETSHOEBOX on any extensions (apk is just a renamed zip), then I think its could work without needing copy to the SD card and prevent bloating memory.
Howover SHOEBOX does not support directory, which is important for me for GETFILELIST() usage, which by now just list all files in the shoebox.
But a area ould been something like SETSHOWBOX("DATA$/directoy", "MEDIA$/directoy"). That mean if directory is set, the GETFILELIST() would simple just list matching files and dirs. So if nothing is wrote, its would still been ignored (because its would match all files).
I also found this:
http://developer.android.com/guide/topics/resources/providing-resources.html
I thinking we could use res/raw rather than assest folder? Howover we might lost folderlist here, so a resources.sbx (and any other sbx files) in main Media folder could do a auto copy to that if it's a android?
The current copying and approach to it is causing some problems, to be sure.
Quote from: BdR on 2012-Apr-15
What I've noticed is that when I install an APK file and start it for the first time, it takes a very long time to start. It only shows the top bar with batery and time, and a bar with the app name, the rest is black screen. Then after a short while, a dialog appears: "<app name> is not responding. Would you like to close it? wait/ok". I press wait a few times and finally give up and close the app. Then I reopen the app, and it usually seems that some (in some cases all) graphics files are missing.
I get this a lot and/or apps failing to launch the first time after copying the media files then needing to be restarted. Example feedback:-
"When running Pow Fish for the first time, the game takes 10+ seconds to get to the splash/loading progress screen. I don't know what's going on but that seems like too much time staring at a blank screen. I've seen this four times installing Pow Fish Free and Pow Fish on my Nexus S and Samsung Tab."
what if it displayed a waiting message?
Its should do that or need to respond.
Also files that been in res/raw folder should been access directly as they should not been in resource file (testing when possible, but my pc died today), and could access directly.
That would prevent assest copying (and prevent freeze), but it does have no folder support (hence the shoebox idea), But still much better if we could test using that folder for Media use.
files in res/raw cannot be accessed from the command line (try to "type" such a file), IIRC.
A waiting message to explain that the game is installing for the first time and will need some patience would be helpful. :)
I do can't check when done. it's might not work which command line (it's sandboxed), but would been tested with fopen and such directly from glbasic)....
Alternative, the java assest copy could just do that in a thread and create a finish.txt when done to been checked under loading by glbasic. Mightbeen th easiest way by now to prevent hanging.
But I don't like it's use double memory due that, so I hopefully the source file can been deleted too.
Quote from: Kitty Hello on 2012-Apr-17
files in res/raw cannot be accessed from the command line (try to "type" such a file), IIRC.
On stackoverflow someone mentions a way to access the files in the res/raw folder, although I don't have any clue if this works and/or if this can be integrated in GLBasic..
android getting pictures from drawables (http://stackoverflow.com/questions/4733874/android-getting-pictures-from-drawables)
QuoteIf you would like to have full control over resource bits, you'd better put it either in res/asset or res/raw folders and then get access to them as:
InputStream is=this.getResources().getAssets().open("drawable.png");
//
is=this.getResources().openRawResource(R.raw.myDrawable);
I "could" try to make the copy of the assets file only when you access it. That would make the loading of the game a tad slower then. But! The lowercase/uppercase insensitivity is definitely broken then. You will have to make sure what you use.
...or I could convert it all to lowercase when building the app...
What do you think? I think that using an "loading" screen at the first start might be the best.
Also, when you move an app to the SD card, the copied data should be on the card, too. No?
The loading screen would been automatic accour if attest was copied in the thread by now.
It's easy to wait in a loop for checking when finish.txt exists by GETFILESIZE(), then the thread is finish.
Also it's normal on Linux as big and small letters is different and should not been changed. So I have no problems with that.
Copying assets as the program requires it would be useful. At least this gives us a way to display our own splash screens.
If you can display a 'loading' screen at the start, you could make it just a xml android view, which allows the use of images put in one of the folders - so you could make it display "splash.png" or something like that, copied by GLB (like 'icon.png') on compile.
The problem I found earlier is that in order to display an android 'view', the initialising function where the files are currently copied has to finish first - so you need to find some way of moving it out of that.
and yes I like the idea to copy the assets when required, even that mean a bit longer loading time. I dont mind if its copied and stay on the sdcard as well. That due not all assets mightbeen required in the startup or been used at all....
I also don't mind for the case sensitivity, since its normal on Linux/Unix based systems anyway and should been that.
I do still mind the easiest mean a while fix is just copy the assets in a java thread (so it allow glbasic to been init while copy and wait until finish.txt, and eventuelly splash.png files popin in the data folder when found).
I experimenting with that when I got the new parts for my PC (that died yesterday).
OK, next update will not block when tfiles are copied. It will display 7 "o" (6x3 square) and change them to "O" so you have a tiny animation while it's copying.
It's not beautiful, but also not ugly. I hope you can live with it.
If not, write a scalable idle animation for me ;)
Sounds good. I guess we could mess with the code anyway if we really wanted too. Isn't it funny that the difference between a blank screen and a series of moving "O"s is so large to a user?
It all stems from early computers - you dont know whether a blank screen signifies that the computer is doing something or has hung...
It is always good to let the user know when long operations are in progress for the previously specified reason!
Excellent sounds great :good: looking forward to the update.
Question; does it now also recover when the copying of media files was interrupted? I mean, when the (ever impatient) user presses the back button during copying, or if he presses the "clear data" button in the app info screen..?
Oh. I have to deal with that yet.
I also experimenting with copy assets in a thread. I got that actuelly to work.
I have attachments (*-java not supported)... no I need to uploade it to dropbox:
http://dl.dropbox.com/u/3236515/GreedyMouse/SDLActivity.java
In Glbasic you can co that if its a ANDROID device (so you have a idea how to do):
// WAIT FOR ASSETS COPYING
IF PLATFORMINFO$("DEVICE")="" OR PLATFORMINFO$("DEVICE")="TOUCHSCREEN" OR PLATFORMINFO$("DEVICE")="KEYBOARD" THEN SLEEP 250
REPEAT
LIMITFPS 10
DRAWRECT 0, 0, 32, 32, RGB(RND(255), RND(255), RND(255))
SHOWSCREEN
UNTIL PLATFORMINFO$("TEMP")<>"INSTALLING" AND PLATFORMINFO$("TEMP")<>""
IF PLATFORMINFO$("DEVICE")="" OR PLATFORMINFO$("DEVICE")="TOUCHSCREEN" OR PLATFORMINFO$("DEVICE")="KEYBOARD" THEN SLEEP 250
as you can see I abused PLATFORMINFO$("TEMP") little abit, which say "INSTALLING" under assetsCopy() and change to the correctpath when its finish.
Yes I only using a blinking curser, but could use graphics or such (which can been loaded soon the graphics file exists).