I am building an app that shows user's FB friends' location on a map with their profile pic as the map marker icon.
After downloading friends' pics, I stored them on ArrayList on a global application object and then show them on the map.
I've realized that I am spending a lot of heap memory for doing that.
I guess the right way to do it will be by storing them on the external storage, but I am not sure how to do it. Or maybe use SQLite database.
So my question is, what is the most efficient way to do that process? keep in mind that when a user's friend connect to the app, the app should show him on the map in real time.
Using ArrayList to store images does not scale very well, a better approach would be to store them in a database using Blob as described here:
How to save images into Database
Another way of doing this if you're not too comfortable with object persistance, is saving your images to filesystem and simply storing in a database table the pathnames to the images, so you can retrieve them when needed.
Related
Is it a good idea to store images retrieved from the web server via a web service in SQLITE DB. I am working on this android app that retrieves a lot of images from a web server and places them in a listview. And I would like to store the first 100 images in some storage area within an android device(That is after compressing them.) when a user first opens the app so that the app doesn't reload a fresh the next time the user opens the app . So, I am looking at SQLITE as one of my top storage options and I am not sure whether there could be a better way to doing this for the sake of improving the app performance. I have seen the question asked at Should i store images in SQLite database? and its answer, which a little fuzzy to me. Your opinion is highly appreciated. Thanks in advance.
Depends on the size of images - If the returned result of your query is going to be more than 1 MB (the binder limit) then you would have to store them as files and only store the URIs in the dbs.
For example you can look at the Contacts Provider - the thumbnails are stored in the db but the full images are not - only URI of the full image is part of the contacts database.
The question you linked too explains the best practise.
Generally, you should store the actual image files in the filesystem or memory card of the device.
Then your app can find references to them in your database
e.g.
SELECT avatar_image FROM profile WHERE user_id = 1; would return the local device file path of your stored image that can then be loaded into your ImageView.
I want users of my app to be able to view a gallery of profile photos on their phone but I'm not sure about the best way to store the gallery on the server? I'm using Postgres and a Java web service.
Should I store the images (or only a thumbnail) on the database or store only the paths and use a separate web server as I have read some people do? I wanted to make it as Android-based as possible so I wouldn't have to rely on having a web server to serve photos, but is there no way around it?
I have read about Postgres extensions to hold image files but I don't know if this is the most efficient way or not (I suspect it wouldn't be).
It really comes down to the size of the photos and how many of them you plan to be storing. Sometimes the database can be a viable option to store small thumbnail images, but generally this probably isn't the cheapest or most scalable solution but could avoid system complexity for a small project. For most projects I would go for file system/blob storage for images.
You should store both your full-size photos and thumbnails in the file system and store only paths in database. This would be more performance efficient.
You will probably need web server in order to protect who can see which photo.
I am parsing a Rss feed using sax parser in android. I am able to display the data online when net is connected but i also want it to work for offline use and update it when it gets connected again to internet / wifi. I have no clue how to go about it.
What should be my best approach now ? should i construct Sql database ? considering i have images as well.
Or there is any other simpler way. I would prefer simpler way.
I need some further suggestion on the Sql database approach here, First : My rss feeds gives image url links which i diplay using bitmap and insutstream at runtime but now for offline purpose i need to save complete images like whatsapp does right ? is this right ? if yes how to save complete images in database ? And last i want to save the complete database on sd card not in internal memory , storing data on sd card will work fine or it will create problem ? because whatsapp stores quite a data in internal memory !! if storing on sd card is not a problem how do i store complete data on sd card ?
This depends on how long you want the data to persist. Ask yourself:
Should this data be available to the users after rebooting the phone, or after force closing the app? Should it be available regardless of the last time I had connectivity, as up to date as possible given that?
In that case, then yes - you should use a database. Android has a number of built in helper classes for sqlite databases.
http://developer.android.com/training/basics/data-storage/databases.html
Which should get you started.
The images are pretty straight forward as you'll just stash a reference to the image(s) in the db. You would of course write these images to disk as well (on the sd card or some other place...) See:
Save bitmap to location
Your other options, afaik are:
1) SharedPreferences (not really suited to this).
2) Serializing your data and writing out/reading in from some file.
If you're still looking for more information on Database concepts and Android, here is a very good tutorial on the topic:
http://www.vogella.com/articles/AndroidSQLite/article.html
You can use droidQuery to download the RSS Feed and cache it. Working off of this gist, which expects you to use the android-rss library, you can add the following cache flags to your AjaxOptions object:
.cache(true).cacheTimeout(AjaxCache.TIMEOUT_NEVER)
This will make it so the response is cached until you explicitly call:
AjaxCache.sharedCache().clearCache();
Which you can do after the network is connected (for help on this, check out NetWatcher).
Note that using this cacheing mechanism allows a very simple solution that will only store as long as the app process is live. If you want to save across sessions - so that if the user opens the app later and is not online, you will want to use something more complex and long-lasting, such as SharedPreferences or SQLite. A good list of options can be found here.
I need some advice. I am doing a grocery list app on the android platform. I am planning to add product images and name to the listview. I am using MySQL and php(using XAMPP localhost) to display the data. So far i was successful with the text display using AndroidHive's connect tutorial.
My question is how should i store the images:
Upload the images to the database using datatype BLOPB
or
Transfer the image to the localhost(htdocs) folder then store directory path(using varchar datatype) [not sure if its possible but I have done something similar in asp.net]
I have seen some example here but not too sure which would be easier for me(beginner level). Thanks!!
Its better if you store images to localhost and use the associated localtion in db.
Because, converting image files and then storing it database would be difficult.
On the other half, it would affect your DB size a lot.
Storing data at localhost would be effective as the size of local disk is not a problem. Moreover, you will have access to image files directly.
I have an android application that allows users to upload images to their account. Im storing the images as longblob files in a mysql db and pulling them from that but I have read on here and other places that its more efficient to store your images in a file system. I know it will work for my alpha to show but its already sucking up space in the db.
Ive seen plenty of people on here and other places mentioning file systems over using a db however....no one makes any references to specific file system software or set ups. Ideally I need a system that would allow for the fastest retrieval of images from it and it has to work with a query from php.
Any tips on the matter would be awesome :)
You could store the images on the file system, and use the database to keep a file-pointer, which is simply the path to the location of the image on your system. Then, use a query to fetch the location, and use that as you would for any image.
This thread on DaniWeb shows how uploads could be handled:
http://www.daniweb.com/web-development/php/threads/162230
Also, use relative paths in case you wish to move the location of the images in the future, as mentioned in the chosen answer here:
When storing Images in the File System, Use relative paths or absolute paths?