where do you store a default image on internal storage of android?
Suppose I want to have a certain image on the main screen of my map. Also, there is a menu option that lets the user select an image from the gallery and once selected, it will downsize/crop the image and store it on internal storage for the app (using something like here). If I understand correctly, then the image will persist even after the app is killed.
Now, there should only ever be one image at a time so the previous image file should just be overwritten every time the menu option is run. However, if the user does not change the image, there should still be some default image file that will display, where should this image be stored in my project?
Alternatively, should I just keep a default image in my drawable or raw resource directory, and keep a boolean flag to know whether it is necessary to load another image?). However, I would need 开发者_StackOverflow中文版to make sure the boolean value persists after the app dies. Possibly using shared preferences?)
Any kind of image that comes with your app should be in your drawable resources. Simply drag a PNG or JPEG file into your res/drawables folder. That's by far the easiest way, and it's easy to maintain for you.
Use BitmapFactory.decodeResource()
to create a Bitmap from that resource, or use BitmapFactory.decodeFile()
if that custom image is available.
I don't know your app, so I don't know how you decide whether or not to use the default image or the custom one. You could check for the existence of the file, if that's a valid criteria, or you could use a boolean in the shared preferences like you suggested.
精彩评论