memory of drawables, is it better to have resources inside APK, outside APK or is it the same for memory?
I have an application that draws a lot of graphics and change them. Since I have many graphics, I thought of having the images outside the APK, downloaded from the internet as needed, and saved on the files application folder.
But I started to get outOfMemory exceptions.
The question is: Does android handle memory different if I load a graphic from APK than if I load it from 'disk'?
code using APK:
topView.setBackgroundResource(R.drawable.bg);
code if image is outside APK:
Drawable d = Drawable.createFromPath(pathName); topView.setBackgroundDrawable(d);
Thanks
Daniel
Asked by: Steven663 | Posted: 25-01-2022
Answer 1
No, internally they are handled the same. Most likely, you're leaking the images, or not cleaning them up as quickly as you could. Try calling Bitmap.recycle();
once you're done with an image, to force Android to clean it up.
Answer 2
At runtime, the memory footprint you're seeing should be about the same no matter which way you load it. Android will use a utility to byte-align resources internal to the apk which should improve loading times.
Answered by: First Name622 | Posted: 26-02-2022Similar questions
resources - How do you use Android R Drawables without using XML?
http://androiddrawableexplorer.appspot.com/
I want to be able to use these drawables inside my projects, but my projects are generated at runtime. I only use XML to define new activities, because quite frankly, I hate working with XML from within java. I'm looking for a mathod similar to this. One that doesn't use any XML to 'findByID' the component i...
resources - Drawables by country Android
I'm translating my apps to a few languages but now I'm struggling with a problem! I a few images with text on it, there is a way to provide drawable resources using country code? If I add the drawable to my apps using the country code It will increase the size of the app? I don't wan't have an app that is now 1MB to be 4 or 5 just because of those images.
Thank You!
xamarin - How to build an Android Library that contains resources (layouts, drawables, etc.)?
I am building an app (using xamarin) with a "pro vs home" scenario: Theres a professional version and a home version, targeting different customers/scenarios.
Yet those apps share some functionality and UI.
Is it possible to build a class library for android, that contains resource files like layouts, drawables, strings, etc., which can then be used in multiple android app projects?
Batch getting many bitmap resources on Android
I have a long series of graphics -- icon1_0.png, icon1_1.png, icon1_2.png..., icon12_0.png, icon12_1.png, icon12_2.png -- and I'd like to package them with my android application. Ideally I think I should be able to load them as resources but the resource id's are set up as java identifiers. Of course, java identifiers can't be assembled at runtime. I have to ask for R.drawable.icon12_00 so I cannot set up a loop
Why is Android looking for QVGA resources in the wrong order mdpi > hdpi > ldpi?
I'm trying to do some testing with a QVGA emulator and I find that it looks for an image resource in the mentioned order.
drawable-mdpi 1st
drawable-hdpi 2nd
drawable-ldpi 3rd(it does get found only after I change the name of the image in the other two dirs for testing)
I would expect it to be ldpi first.
When running other emulators (HVGA and WVGA) they use their appropriate drawable di...
android - What's the better way to pass resources?
Need some advice from you experts out there. I've just started with Android
programming and while I finally got what I want my "Hello World" to do, I feel
as if I'm bludgening my way through rather than grasping concepts.
I created three EditText boxes. Below those I created three Spinners. Pick a
number in the Spinner and it will show up in the corresponding EditText box.
Spinner 1 correlates to EditText 1, Sp...
java - It is possible to include layout and other resources in an Android jar?
I'm building a jar so that other developers can use the view I create in their Android applications. I'm wondering if it is possible to use a layout resource in my jar so I can build the layout of my view or if I need to build up my view programmatically. Similarly, can I include image resources in my jar file?
possible xml elements in Android resources xmls?
I recently came across a forum post in the android developers group. (link below)
http://groups.google.com/group/android-developers/browse_thread/thread/ef3bdebcb715b385
It has one post which contains following xml. It is xml file which can be used in drawable folder.
&l...
android - Changing locale: Force activity to reload resources?
So I have a language setting in my application. When the language is switched, I would like all the textviews etc to change language immediately. Currently I just change the locale in the configuration, so the language has changed when the user restarts the activity.
An ugly solution to my problem would be to make each textview load the new resources each time the language is changed. Is there a better solution? Pe...
android - Language resources in separate APK?
I'm wondering if it is possible to create a separate APK file which contains only language specific strings and somehow persuade my program to try to read the string resources first from that package's resource and then from the program's own resources... I would like to have a main program with 2-3 mayor laguages and the rest of the languages would go into a separate language pack. (This is to keep the main program size s...
android: where are the image resources allocated?
Is there anyway to get the actual images used in resources? e.g., I want the two png files in CheckBox in starstyle? Which directory does andorid keep them?
android - access resources of an apk
I'm thinking about putting a .txt file in res/drawable or in res/layout to have it in the apk when the application is packed, and then after install to open and read from it to perform some tasks. Can this be done? If yes please let me know how can I access the file, as I don't know it's path.
android resources in apk
In my android development project under the folder res there are all the resources my application uses. The size is 3.11 mb and contains 1013 files . On the other hand in the apk there is the folder res with all the resources as well , but this has a size of only 760 kb and contains only 332 files . Now does this means that not all the resources are packed? If this is the case what ha...
Still can't find your answer? Check out these communities...
Android Google Support | Android Community | Android Community (Facebook) | Dev.io Android