Image URL in App or in Database - android

I am making an android app which is going to need a lot of pictures. But I can't have them all in the app since it would be like 10 gigabytes or something. I have read some other questions where they say its smarter to store the url to the pictures in a database. My question is, should the image url be stored in the application itself or in the database?

The DB is a part of the application itself. Is it not? If you are talking about hard-coding , keeping them in DB is better keeping extensibility in mind but would involve extra call to DB.
Hard-coding them would be better performing (How much, you need to test that).
Alternatively you can make use of build tools by storing the urls in a configuration and replacing them at the time of build. While this solves above two problems, It adds complexity to the code.
So everything has its gives and takes, you need to decide what to chose on your requirements and priorities.

If you store the URLs in a database, you are able to manage your images easier, as you don't have to hardcode everything.

store URL in a DB will more preferable. And you can load the images using picasso library would better easier and comfortable way.

Its always better to store image url's in a database, whether that database resides on your phone, or on the server and you fetch it from there using rest services is upto you.
You can use multiple libraries for image lazy loading in your app.
[1]: https://github.com/nostra13/Android-Universal-Image-Loader "Universal Image Loader" is by far a very good third party library.
You can also add your own lazy loading algorithms by creating a basic Thread Pool.

Related

Storing Images in android from web services

I am able to handle images and text from web URL's in android using AsyncTask, but have a separate question in mind.
Which approach is best suited for storing pictures for one time loading?
IE: Either in an SD Card or in SQLite DB.
If you want to store images for just one time loading, you don't need to store it in Sdcard. You better use a library like Glide or Picasso. It does all the hard work of caching and managing memory for you. It has very simple API.
Glide.with(this).load("http://goo.gl/gEgYUd").into(imageView);

Saving and retrieving images from internal or external memory in android

I want to save the images fetched from server for once and from next time i want to check first whether images are stored or not in device, if not then again it should fetch from server and store in user's device again, and if yes then application will use images directly rather than fetching from server again and again. It will be useful for enhancing the speed of application. Basically my application is fetching multiple images from server so i want to save those images on user's android device and from next time application should fetch from device. I think you got my question.
The simple way:
You can use Picasso.
It is a simple lib which provides image downloading and caching.
In my opinion it might not be the fastest, but it is pretty simple and intuitive. It does its job well and none who I asked complained about it.
Picasso
Other libs:
UIL
Volley
Glide
fresco
To make it short. There are lots of other libs. An awesome comparision of the most Populat ones can be found here and here
The do it yourself way:
You can also write you own caching logic with a LRUCache. Which is also pretty simple.
Take a look at:
https://developer.android.com/topic/performance/graphics/cache-bitmap.html
The LRUCache is just a Memory Cache so you might also want to use a DiskLRUCache

Dynamic Loading in Listview Android

My DataBase contains 1000's of images on server , I have to display these images in ListView in Android.
I have to develop similar List like that in the Flipcart app(If User Scroll then download Images) and store a local copy in SQlite and display from that SQlite database.
(In future if connectivity would not be there then also I would be able to run my app)
because Images will be available in SQlite.
Please suggest proper Solution for that.
Use of loaderManager or something else please suggest
I don't advise towards storing the images themselves in the SQLite database. The database will become slower to use and more cumbersome. Also, I think you should not implement such complex functionality yourself as there are many ready to use open source solutions.
There are a lot of solutions that allow you to cache the images on the file storage. They work transparently - when you request url they first check the local cache and only if this check does not exist they will make network call. Most of them also will display default thumbnail until the network call succeeds. Basically I think this is the best you can do.
I, myself have used Universal Image loader for what I describe, but out of this thread you can find many alternatives.

Android best way to retrieve images and view them from external source

I'm going to be making a wallpaper app but need some guidance on how I am going to be able to store, retrieve and view the wallpapers.
Will I need to make use of ImageView so I will be able to display the images?
I'm going to need some sort of database/website to store all of the wallpapers on. What would be the best thing to do, use a database or a website?
How would I go about retrieving the wallpapers from my chosen source?
Any help/advice would be appreciated, thanks.
A common practice is to use an rss feed of images. Then, just hook up your app to the rss feed and have it check for updates periodically.
Here is a reference on reading xml (rss) in Android:
http://www.ibm.com/developerworks/opensource/library/x-android/index.html
Good luck.
you can try aquery android library for lazy loading image. this library store images in cache memory so you not need to store it externally also it will take some time for first time loading image from web but once it load in your application then it will automatically store in cache so second time take very less time to display also its less time consuming then other lazzy loading methods..below code may help you.....
AQuery aq = new AQuery(mContext);
aq.id(R.id.image1).image("http://data.whicdn.com/images/63995806/original.jpg");
You can download library from from this link
Personally I would use a database. But the easiest option would be to use the 'res/drawable' folder in android I guess.
If you stored them on the internet and haven't got connectivity, you can't get your images, so users won't necessarily like this.
To get at them from a database you'll likely have to know some SQL or know someone who knows a bit of SQL. The advantage of storing them in a database would be that it's one neat package and it is portable.
Don't worry about using ImageView it, you just need to get the image from the source (database /filesystem etc..) and give it to the imageView

Idea to download images in android

I'm making an android app, here the images are getting from Cloud, is it good idea to download images and save it & use it further. Or download images every-time user uses the app, what idea you prefer is the best?
Because downloading images always is slow & its bad i know but at some point if the images are updated then how to get to know about it?
You should definitely cache your downloaded files!
Do it in your internal app directory where only you do have access to (or otherwise external storage, thats still ok).
Bandwidth and connections are always expensive and should kept low as much as possible.
So your user can see images fast even on a bad connection and your app doesn't waste his valuable bandwidth of a users data plan.
Maybe this could also help you:
https://github.com/novoda/ImageLoader
http://www.androidhive.info/2012/07/android-loading-image-from-url-http/
Make it easy on yourself and use something like Android Smart Image View. It takes care of loading and caching, and it's just about a drop-in replacement for Android's ImageView. Universal Image Loader is another alternative, more configurable, but not as quick to implement.
I used https://github.com/nostra13/Android-Universal-Image-Loader
but I think you not want only download and cache.
these no trick ,if you want check weather the image update or not, you can add metadata for image, just like md5 .
in html and browser, you can set expires header for a image:
enter link description here
but in android app, you control all yourself.
Downloading images and saving them is probably the best way to do it because you don't want to download the same images over and over. If the images are updated you can delete the older one and download the new ones. Just make sure you don't download/save a million images. Take a look at this library. It has a built-in cache on sdcard/external sd.
Downloading images from the net for display, with possible requirement of caching is a very common problem that many people have solved, you can try these solutions to see which fits you:
Ion (https://github.com/koush/ion) - very flexible and feature complete, plus it can download more than images but JSON, Strings, Files, and Java types as well. The part that I really like about this is that it can automatically cancel operations when the calling Activity finishes, so users don't waste time & bandwidth downloading images that will no longer be displayed
Universal Image Loader (https://github.com/nostra13/Android-Universal-Image-Loader) - equally capable for most use cases but for downloading/caching images only

Categories

Resources