How do I load resources and classes at runtime in Android? - java

I am developing an Android application where additional content is downloaded at user request. This includes images, sounds and classes. What I need is to load those resources and classes at runtime and use them. Is there a way I can do this?
Edit: I need to do this for Android 2.2 or higher.

Take a look at AsyncTask and Loaders API. This will provide you the facilities to download images, resources... in a background thread.
http://developer.android.com/reference/android/os/AsyncTask.html
http://developer.android.com/guide/components/loaders.html

I would use AsyncTask and cache them to the local memory, SD card or hard drive. You could start the AsyncTask on the load, cache the data to memory, then call it when it is needed. Here are a couple links that could help you with this:
AsyncTask:
http://www.peachpit.com/articles/article.aspx?p=1823692&seqNum=3
Caching:
http://developer.android.com/guide/topics/data/data-storage.html
Hope this helps!

Related

Storing bitmaps in android studio vs fetching with url

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.

Android best practice - download pictures

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.

Best way to load assets in android java

I have one android activity with a lot of calculations and everything is ok, but in the final version of my project I need to load a lot of bitmaps and sounds in the same activity and it gets a lot slower than it should be.. Sometimes the activity chrashes itself.
So, is there any advice how should I load all the assets? Should I declare them in separate class, or what?
Basically you only load those assets when you need them and unload them if you do not need them. (Lazy Loading)
Because mobile has limited memory and I am imagining your files are really big you must be careful on how you will manage those files.
For image I recommend this link and try to optimize your image as good as possible
For sounds kindly look at this class and this discussion about loading sound files
OutOfMemoryError when loading large amount of data in Android
Android SoundPool – How to check if sound file is loaded?

How to take a picture of in panaroma mode?

I want to make an application that allow the user to take a picture of text either from android device Gallery or from android Camera application in a Panorama mode .But i can not find any source or tutorial to do this.How can i do this in my application? how to make an application that take picture from android camera application in a panaroma mode?
Thanks in advance.
I don't know if it's still actual for you, but hope it will be helpful for someone.
Panorama feature is already implemented in standard android camera at least since Android 4.0 (perhaps it was available in even earlier versions but I'm not sure, you can check it), so since source code is open for everyone, it might be the easiest way just to copy required functionality.
Although you can download source of apps from https://android.googlesource.com/ (you want LegacyCamera or Camera), you can't just open project of any standard app in Eclipse or other IDE. For example, LegacyCamera depends on Gallery2 and other dependences that might be hard to be resolved.
I spent several days trying to move panorama feature to separate project. You can download it from here: https://github.com/yankeppey/PanoramaSample . Several remarks:
Functional core (creating one panorama image from several ones, progress notices, etc) is on native part.
I used java code from from LegacyCamera which was used in Android 4.0-4.1, not 4.2, because it was significantly easier for me. Native part is taken from 4.2, it has only minor changes inside and almost the same JNI interfaces.
This project is just to help you move panorama feature to your own app, it's not like kind of library, don't expect clean code without bugs, it's just pretty dirty and buggy project. If I have time I'll try to make it cleaner, but there is no warranty :)

Retrieve multiple images from web source with one http request for android app

I am attempting to build an android app and in that app I have a list view, which I would like to have thumbnail images in. The images are stored on a server, and they are all in the same folder (e.g. http://myserverlocation.com/images/dining/myImage1.jpg,myImage2.jpg, etc). What I want to know, is if there is an easy way to get all the images (approx 25) using ONE http request, or connection. What I want to avoid is making 25 http requests, one for each image, to get all the thumbnails. I'm familiar with AsyncTask, and BitMap, but I haven't seen anything on this site (or the internet) that talks about getting multiple images with one call. I was hoping someone here would have an answer for me, as to whether or not this is possible. I'm open to any suggestions on how I might be able to accomplish this task, without using all the phones resources and/or memory.
Thank you!
If you are controlling the web service, I would highly recommended storing a zip file and retrieving that. I believe that Android likes to play with bzip, but that may be wrong.
Either way, I remember reading on the Android Dev site or watching a Google IO talk and they suggested to zip it before you ship it.

Categories

Resources