Android Application pictures how to download/store them?
I inherited an application that is 8M in download size. It has a ton of graphics...was wondering 开发者_JAVA技巧the best way to handle this? If I remove all the pictures the app is only 300K so it would be nice to either offload these or load them upon first boot up of application. So my questions are, Whats the best way to handle pictures either SDcard or SQLite DB? and the Second is how to download the files on first boot up from say my website or outside database/webservice.
So the situation is not so simple. If your are planning to do this you have to think about few things first.
- Bitmap drawables stored in your res folder can be optimized during build process. For more info http://developer.android.com/guide/topics/resources/drawable-resource.html#Bitmap
- All your drawables are with assigned id and you can easily access the through Resources.
- If the phone has no network connection how are you gonna download your resources.
You have to think about if these graphics are part of your application and should be included as resources or they are in same way additional functionality and you can download whenever it's possible.
The best way to store images is in the File system, Databases are no such good to it.
To download the images, you can use an URLConnection and use the BitmapFactory.decodeStream to parse the result from the URL InputStream.
Them use the Bitmap to write on disk.
精彩评论