Android, files in media folder automatically copied to data?

Previous topic - Next topic

BdR

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]

spacefractal

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).

Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

Moebius

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.
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

BdR

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?

Kitty Hello

Hm. See what I do in the Java file. Can anyone assist?

BdR

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?)

spacefractal

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:

Code (glbasic) Select

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).
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

spacefractal

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?
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

Wampus

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."

Kitty Hello


spacefractal

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.

Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

Kitty Hello

files in res/raw cannot be accessed from the command line (try to "type" such a file), IIRC.

Wampus

A waiting message to explain that the game is installing for the first time and will need some patience would be helpful. :)

spacefractal

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.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

BdR

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
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:

Code (glbasic) Select
InputStream is=this.getResources().getAssets().open("drawable.png");
//
is=this.getResources().openRawResource(R.raw.myDrawable);