简体   繁体   中英

android application require a certain directory in the SD card to run

We are building an android application, however this application have to make sure that there is a directory tree and some files in the SD or internal storage.

I think maybe I can package these files and then extract them to the user device.
However I have two problems:

1 Where to put the files? The asset or the raw folder?

2 Where to do the check job? Inside the activity? Is it necessary to create a Application object for my application and do this job?

Thanks.

1 Where to put the files? The asset or the raw folder?

Since you can read files from both folders, the possible difference is on reading speed and file size. Files in assets are zipped, so they take less space but probably takes a bit more time to read; while files in raw are not compressed, so no decompression is required to read them but they do take up the full space.

2 Where to do the check job? Inside the activity? Is it necessary to create a Application object for my application and do this job?

The least you need to do is check it in your launcher Activity. But since the user or even other apps can modify the SD card at anytime in any way they wish, it's better if you do the checking when each Activity is resumed, and possible also before each usage.

1 Where to put the files? The asset or the raw folder?

This depends on what kind of files you want to put. So you should understand the difference between asset and raw. This similar question - The reason for Assets and Raw Resources in Android - may help you

2 Where to do the check job? Inside the activity? Is it necessary to create a Application object for my application and do this job?

This depends on your design. You have to consider performance. For example, you can do the check job when your Activity resumed, but it may take a long time, which may cause bad user experience. So for this case, you'd better do the check job in a thread and send notification to front-end when checking finished. Alternatively, you can do the check job in service when system booted. or do the check job when your Activity created.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM