Android app download pattern involving same image on different devices/screens - android

Let us suppose that I made an android app that has an image in it.
I had kept the same image of different sizes in xxxhdpi, xxhdpi, xhdpi, hdpi, mdpi and ldpi Drawable folders.
When a 'hdpi android phone' downloads my app, will it it download the image from all the Drawable folders or just the 'hdpi' Drawable folder ?
I wanted to know if using separate images for separate screen types increases the app size or not.

Yes the download of the APK always includes all resources you have included.

Your apk will be downloaded with all the internal resources(Images,raw directory etc..) and your APK should not be above 50MB if your APK size exceeds this limit you may have to use seperate Expansion files. Description Here
EDIT:
You can try Multiple APK Support if your apk size exceeds 50Mb limit and you still want to embed all resources inside your APK Described Here

Related

Resources not found, but only on seemingly random devices

I'm getting quite a few crashes on a live app.
Fatal Exception: android.content.res.Resources$NotFoundException
Resource ID #0x7f080389
The resource exists.
It is a PNG and it's set using.
icon.setImageResource(a.icon);
where a.icon is an int with the id of the image required. I'm 100% sure the value here is fine.
There is no obvious pattern in regard to device and operating system. With the same phone and os version in testing and most live users everything is fine.
The app is distributed on Play Store using a package.
My current theory is that some people are getting the app via some other place (the app is not available everywhere) and the APK they are trying to use does not match the screen density of their phone.
Is this reasonable (and can I prevent this) or is there another possibility?
Cheers.
This exception is coming because image is present but not for all the resolutions.
Device will check the image in all the drawable folders which are equal or lesser resolution to resolution of current device.
Various screen resolutions are mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi.
Example: if you image is present in drawable-xxhdpi folder and device is of resolution xhdpi. Then it will check for image only in drawable-xhdpi, drawable-hdpi, drawable-mdpi and default drawable folder and may result to resource not found exception.
Hence you should add image to all the various resolution folders as per the quality. xxxhdpi should have sharp and high quality images.
Also, it is recommended to add default images in the default drawable folder to avoid any resource not found exceptions.
Hope it helps.
Released the app as an APK. No issues at all. Definitely something not quite right with the package splitting.

Is still in new generation Google App Bundle need mdpi or xdpi resource files?

In this year Google annoucement new app bunle for android or Google
Play users.
Good, but already know it we are using still xdpi, mdpi, xxdpi, resource files.
So, app bundle split your images, language but if we delete xdpi, mdpi, xxdpi files and we protect xxxdpi resource files and we reduced %40 app size.
I mean if you delete other resource images (in res folder) except xxxdpi,
will the app bundle be a problem for devices?
If you provide only the images in the xxxhdpi density, your app will run slower on some devices since the Android platform will need to scale down the images on the fly before rendering them. It also takes CPU thus to perform the scaling, thus taking on the battery of the users.
So although this is an option that is perfectly compatible with the Android App Bundle (nothing will crash -- all the users will get your xxxhdpi resources), it will have negative consequences for your users, so you shouldn't do it.
**anydpi**: These resources take precedence in any dpi. So even if you have mipmap-hdpi or mipmap-mdpi matching with current devices density, resource from mipmap-anydpi will always be picked up.
I have been using it for adaptive launcher icon for my apps and it generates the xml and there is no need for any other dpi dependent drawables.
You can get more​ information by visiting these links.
Anydpi and anydpi-v26
Image asset studio
nodpi vs anydpi
Adaptive icons and more
Couldn't put in comment so adding it here

App Crashes. Error Inflating XML. Cant find image because xxxhdpi folder is not there

Switched my eclipse project to Android studio. I was maintaining resources under drawable-mdpi folder only. Now in studio the preview of XML loads images correctly. However when I run the app in a device with resolution higher than mdpi the app crashes, shows error inflating binary XML.
After a long analysis I found the issue that the device was trying to load images from its corresponding density folder which is not available. So I created the folder drawable-xhdpi and put images in that folder. Now the app works fine.
Why android studio can't pick image from other density drawable folder and resize which is possible by eclipse. I can't maintain 5 different drawable folders because there are lots of images.
you have to add "drawable-hdpi" resource directory and paste all the hdpi resources there because currently 70% android devices supports hdpi resolution images.
if you only maintain the hdpi, then it is also ok.
android manages all remaining resouces from hdpi resouce directory.
Android application resource directories provide different layout designs for different screen sizes and different drawables. These different drawables are used by android to support a major range of all the android devices present out there. It's a standard practice to put your resources considering these densities. Coming back to your query:
Why android studio can't pick image from other density drawable folder and resize which is possible by eclipse. I can't maintain 5 different drawable folders because there are lots of images.
For your case,In order to maintain this you could create a drawable with nodpi and put your all resources there. nodpi focus resources for all densities.Your resources should be density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen's density.
Hope this will clear your doubts, for more insight you can also look this.
you don't need to add all images to each difference size folder but depending the size of the image you might need to add images to different folders.
simple example is this can occour once you add high res/size images in normal drawble folder
Skipped 100 frames! The application may be doing too much work on its main thread.
This might not crash your app but will make it's performance down.
and
Different density folders were added later on for Android which means that...
If you wanted to be lazy and just add one asset the best choice would probably be the HDPI asset if your min app target < 8 and XHDPI if its >= 8. This is because the system will scale the resource up and down, but you would still want to start off with the highest resolution possible.
If you want to have complete control over how the assets are scaled then you can by all means provide your own for all / some of the densitys. In practise I generally provide HDPI / XHDPI as above and give all the resource buckets for things like logos / AB icons / App icons etc. I generally find the auto scaling to be pretty good and work for most situations, but will occasionally have to supply and extra LD/MD asset if its a small asset / contains small text etc. Plus if i duplicated all assets for things like XXXHDPI I would get pretty good apk bloat.
You can also use IDEs built in tools to add a single asset for many densitys at once. In Android Studio 0.6 this is File->New->Image Asset and a wizard will appear.
I have never noticed or heard of any perfomance impact of allowing Android to scale assets automatically - presumably this is done in hardware.
It may not look great when auto scaling down to LDPI say so you can optionally provide your own scaled assets for all other densities.
taken from : https://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
Do we need to add all images with different dpi to Android Apps

Does including icons for multiple screen sizes in an Android app impact the installed size

When you include icons for multiple screen sizes in your Android application are the icons that don't apply to that screen size purged when the application is installed on a device? For example, if I have a tablet that has an xlarge screen that has a xhdpi density are the icons in the drawable-ldpi, drawable-mdpi and drawable-xhdpi folders purged when the application is installed (assuming drawable-xhdpi has all the necessary icons)?
Yes. All resources in will be included in the apk. The apk is the installed application; there's no point at which the resources are copied elsewhere before running it. You can confirm this by installing your app on a Nexus 10, then using adb to make it emulate other dpi targets. Even though you've installed the apk when the device was at a xxhdpi, relaunching it at mdpi doesn't kick off another install, the mdpi resources are already there.
A solid strategy for reducing the size is to simply not use large images when they're not necessary. I use conservative 9-patches and substitute xml drawables for shapes when appropriate. If you've done everything you can and you're still concerned with the apk size, you can create multiple apks that target different dpi points.
It has to have one of each of those icons in the apk. So it will increase the size.
Yes it will but you can use programs like OptiPng to compress your PNG Images so the size of the application wouldn't be affected much.

Does Android only install device size's resources?

For the same images, I store several copies of different sizes in my Android project (ldpi, mdpi, hdpi). Now if a user installs my application on lets say a mdpi device, does it only copy the mdpi files to the device, and not use too much storage space? (maybe takes something from hdpi if missing)
If so, will the Android market show the size for 'your' device only, or the size of the full apk?
As blackbelt notes, all resources in an APK will be installed on the device. However, if you really need to restrict this, you can use the Market's multiple APK functionality to deliver tailored APKs to different devices. Google recommends that you use a single APK if possible, but the multiple APK route might make sense if your configuration-specific resources are particularly large.

Categories

Resources