I am building an app in Android Studio and I have a problem. The basic idea of the app contains one Relative_layout with two buttons inside.Every time I press one button it sets the background of the layout to a Random image I have stored in the "res/drawable folder". The thing is that I am going to have a very big amount(larger than 10.000) of pictures(with high resolution) to be stored in that folder. Will this have a big effect on the APK size of the app? And if it does, is there any other more efficient way to store(or connect) a large amount of pictures with an android app?
You have 3 options:
Store the images as local resources, with very high res: Your application size will be huge
Stroe the images as local resources, but with less resolution: Your application size will be smaller
Store all the images on a web server, and retrieve them when you need it(Using picasso is super easy): Your application size will be very small.
You decide.
if the number of images is large, it is better to store at server and load dynamically when required, use Glide(fast and efficient open source media management and image loading framework), you can load image and display with a single line of code.
Related
I have a huge number of files that I need to upload and place in the viewpager. It can be several thousand images. How can I correctly implement the loading of a large number of images so that the application works and does not crash ?
I'm sort of new to managing memory in apps and have a question with regards to bitmaps.
I have many users that can each upload a profile image to be stored in firebase storage.
I'd like to be able to display these images as quickly as possible. The two options I see is
Loading them in the background at start up and storing the bitmaps, then referencing them later when they're needed, or
retrieving them when they're needed using Picasso or Glide and the urls (however this causes a small delay betweenAn when the page is loaded and the images are displayed, it also causes the need for more database calls).
By storing the bitmaps am I screwing myself over with regards to memory? Im testing with 10 made up users right now but if i have a 100 will the app be able to handle it?
Using Picasso or glide is the best way to load the images because they use cache as well, so there will be no unnecessary api calls. Also, they use highly optimised algorithms such as LRU, which can free the object/image which is not used for long time and clear those images from the local cache.
I'm a 17 year old trying to start developing some android games. I've used LibGDX once before and found it a pretty effective tool, so I'm using it again now.
The game I'm making is a choice based, interactive game where you make a choice and then the next scenario happens based on your choice, and it goes on and on until your character dies or you win. I'm expected to have around 200 scenarios by the time I'm done, and currently have around 160.
The problem I'm having is that each of these scenarios is basically a "card," with a picture, scenario description and 2 options below it. Each of these images is pretty big, and if I scale the card images down they start looking pixelated on the phone screen. I'm worried that in just images, my game will reach 100mb, and then with sound effects and everything else it might be like 200mb. This seems pretty inefficient and I don't want potential players to shy away from the game just because of it's size, if they don't have enough room on their phone...
Am I doing something wrong? I apologize for this inexperienced question, I'm really new to Android development.
That isn't too big for modern games but you will need to not include the assets in the apk and either download that when needed or use what Google already thought of for this problem.
https://developer.android.com/google/play/expansion-files.html
These are some steps that can help you reduce your apk size:
Use only specific drawable
Add only specific image size for each drawable directory for drawable-mdpi, drawable-xhdpi, drawable-xxhdpi, etc. You can try removing a drawable directory that could potentially unused by the user, like drawable-mdpi and drawable-xhdpi, and use only the hi-res one like drawable-xxhdpi. Or, you can try using only drawable directory for all the images, so your app will only use one image for all devices type.
Resize your images
Compress your images
If your images are PNG files, You can compress the images without a noticeable change using pngquant. In fact, it can reduce your images sizes significantly (often as much as 70%) and preserves full alpha transparency. Or you can try using pngcrush (I'm rarely using this)
How would you approach this problem:
My app should download different packages of pictures (containing up to 300 pngs, each about 20 kb) and store the pictures on the phone, so i can display them.
I want to upload the pictures somewhere online, so I can change them every time and the user can enjoy the newest pictures. (I upload the pictures not with the app)
I read that storing them in a sqlite db isn't the best option.
At the moment I am storing the pictures in the app, but then I don't know how I can upload and replace pictures on all apps immediately without the need of updating the whole app.
I don't need code or stuff, so don't waste your precious time on that, just some general hints where and how you would store the pictures online, and how android can download the pictures easily.
Take a look at the Glide or Picasso libraries. Those are super easy to use for thread-safe downloading of images.
Personally, I just fetch/store the images on imgur.
If you want to upload a dedicated databse, you'll have to set one up. Some common ones are Amazon, Google, etc. There are tons.
Have a look at this answer. In this answer Picasso library is used to handle image download. Picasso gets rid of a lot of coding and testing to handle image download.
In a project that I am working on, we use Amazon S3 to store our pictures, it's very reliable and is one of the goto solutions right now.
From what I heard Snapchat and some other big firms use S3 to store their picture!
It's also very cheap, plus I believe they have free hosting to a certain degree.
This is their API guide for android.
We use a service called File Picker to handle upload and download from amazonS3, it reduces a lot of work, but I don't think it's a free service.
You can use Picasso for downloading images from network in Android. For storing images Amazon S3 or Google cloud storage can be your options.
Not sure if downloading packages is better than downloading individual pictures (archiving won't save you much space).
As for your question, you can make some kind of API you will query from your app, even a flat file hosted somewhere with changing content would work. Your app could check it periodically for the new address to download pictures from (assuming it will change).
another way is using push messages - sending out a push through GCM that your apps will receive that will notify them about new content available. It would even work when the app is closed.
So I've tried going about animating a button through the example given in this example: Android Developers
and have made a huge (95 pictures) anim-list with Pngs. When trying to run the app and pressing the button, I promptly receive an error about memory not being sufficient. The file sizes are about 170k (12mb in total) . Is this too much for an animation? I realize the serious lack of regard for eventual users' storage space with this approach, but it's mostly for my own use anyway and won't matter.
The images are pretty big and need to be downscaled by the graphics engine however, and this might have to do with it?
Or is 95 pictures too much ? I can make the pictures smaller, right now they're at a whopping 4K resolution, which in hindsight is pretty dumb.
However, I can compress the pictures and make them smaller from the beginning anyway so that's not a problem. I just need to know how to fix this issue, if there's a treshold for how much can be loaded into RAM at a specific time so i can match the image sizes or if there's a way to override the default RAM settings or overcome this?
Don't look at the file size. Image has to be uncompressed so Android can use it. The image size is more or less equal to width*height*4. 4K image takes ~35MB of memory.
Modern devices can allocate 64MB of memory per app. It means that you can load only one such image. Maybe more if your phone has higher heap limit.
AnimationDrawable is for small animations (like 100x100px). If you wish to play such a large animation, you should encode it to mp4. If you can make the images smaller or make the animation procedural - go for it.
To override the memory limit use 'largeHeap' flag or change the setting in the ROM configuration (you have to flash your device with a custom ROM).