What is the recommended approach to retrieve images from server to app - android

I'm currently building an app for learning purpose (new to android programming) that lets the users to upload
image to the server and watch other users images (by swipe the screen for example).
I finally succeeded to let the user upload image to the server and I was wondering how to code the part that retrieve the images from the server and present them in the app.
Assuming I have at the time million images, I don't want the app to load all the images in the same time because it will take a lot of time.
And all the guides I'v seen makes the app to load all the images at once.
So my question is what is the recommended way to do so?
Hope I was clear.
Thanks.

Let's say you have an array with a million images in your server to load in your app that will be shown in a RecyclerViewand assuming a screen can fit about 5 images.
In this case scenario a good approach would be to fetch 10 images at a time and load them in a RecyclerView. Load the first 10 images and once the user reaches the end of the scroll load some more images, add them to the previous retrieved image list, and finally update your RecyclerView to present them. With some effort you may be able to create a Facebook look alike effect.
RecyclerView has methods that will easily help you detect the end of scroll (there are plenty of ways you can find in StackOverFlow). Every time you detect an end of scroll, just upload more images.
This is one example: How to know whether a RecyclerView / LinearLayoutManager is scrolled to top or bottom?

Use FlexBox Layout for better UI Design to show images

https://github.com/google/flexbox-layout
See how this cat images are shown using FlexBox Layout

Related

Imageview down the performance of my app

I am working on an Android app where, once a user clicks a login button, the app launches an AsyncTask to verify account details with a remote server. That part works fine by itself and doesn't make my app slow. However, when you click the login button, it launches a second activity where I have 4 ImageViews. When I added that part of the app, it became significantly slower (from less than a second to about 5 seconds loading time). I load the images into the ImageView from the XML layout file directly, so I'm not sure what I'm doing wrong.
My question is that do ImageViews make your app slow, and if so, how do you optimize their performance?
I was working my own app when I actually experienced this too. The reason is because if the files are to big they take a while to load into memory and set as the Image View. There is two ways you could really sort it out.
1: Get a smaller version of the picture. Smaller pictures come up faster and aren't prone to an OutOfMemory exception which kills the app :(.
2: A better way is to use the Picasso api. I used this APIs to add images in list views, expandable list view with pictures in them. The app was fast and fluid :)
Picasso's api would be your best bet ant it is easy to implement.
Edit:
Here is the link to the site to get the APIs :)
Picasso
The only way I could figure this out is to create an image in photoshop that has all the buttons laid out where you want them on top of the image. Interpret it into your app and put regular buttons over top of the imagebutton pictures that you placed onto your background image. Set the size accordingly to your images of your buttons and then set the background of each button to #null so they aren't seen. Now trying to figure out how to interpret this into orientation view even though I don't think I'll be using orientationview. OH AND CHANGED THE EXTENSION TO A GIF TO SAVE ON DATA RATHER THEN PNG.
Hope this helps I'm sort of new at coding on android as I have lots of experience with HTML .
Cheers
THANKS FOR THE DOWN LIKE I WAS SORT OF NEW AT THE TIME OF NOT KNOW OTHER WAYS TO SET THIS... THANKS THOUGH, MORONS

Thumbnail creation. On the fly or create small image?

The question regarding thumbnail creation seems to get asked a great deal, and each time there seems to be a great many different solutions proposed. From my experience none of the supplied answers are actually sufficient and all seem to have their own flaws.
a) Memory issues when re-sizing
b) Performance issues / slow to render
I therefore wanted to post a question regarding a very common functional requirement that I am hoping someone can assist with.
'User generates a report using activity and takes associated photo using internal camera. The report along with the image path is saved to SQLLite database. User wants to view reports in a scrollable list view at some point in the future. Number of reports could be 1..100'
So given these requirements the questions I have are as follows
1) Given that to data I have not found a reliable / performent / memory optimised way of resizing full size images at run time to a given thumbnail, should I create a smaller image at image capture time?
2) If you need to display many items in a ListView should you use paging or should it be possible to display a 100 items in one ListView?
Thanks
Regarding number 2: What you could do is load a subset first (say the first 30, depending on your listview item size), and load the rest asynchronously and append them to your adapter. This will decrease the loading time of your screen.
1/ Why do you want to reinvent the wheel :) There are libraries that already do for you and do it well. See picasso or AQuery for instance (there are other libraries too).
Basically, they have a thumbnail cache somewhere on the SDcard/internal memory to keep last N requested thumbnails.
I don't know if you are keeping the image data within the database, in which case you may have to adapt one of those libraries to load the image data from the DB and not from a file as it is usually the case.
2/ Why do you want to reinvent the wheel :) There are libraries that already do for you and do it well. See https://github.com/commonsguy/cwac-endless for instance (and google for more)

Best Practice for handling lot of images and textview in Gridview

In my android mobile app, i have list of lot of (more than 200) images and textviews. For that currently i am using gridview.
But my problem is if i am request all that content at once from server then its take too much time to load and render that images and text in gridview which affect user experience.
So i thought of load only 30-40 items at once and then provide load more button at end. But it is not appropriate way to do this thing.
So can anyone please give me other alternatives to do this thing?
fallow this tutorial analyze code and use it.developer tutorial for displaying images.

Android: Best way to Display Images on a screen

This could potentially be a duplicate but I after spending several hours reading about ImageView, ImageSwitcher, Gallery Views, Lazy Loads, and more I decided I should just ask.
I am working on an app and in one of the screens there may be an image or multiple images associate with what I am talking about. The other data for this intent will be pulled from a local database. In the database it will also have a list of URLs of images that are associate with each thing that I am discussing. So I would like to know the best way to display a thumbnail of these pictures (if there are any) on the screen. Then if these pictures are clicked on it can open up the bigger version of these pictures. I don't necessarily want to download these pictures since I don't want to save them locally for the app. Plus I don't want to make the page delay in loading while it waits to download the pictures.
What is the best way to handle this scenario?
I have to caution you, that with newer versions of Android, applications can't make connections to the internet that build the UI directly on the UI thread. Instead, it must be accomplished in a background thread such as ASyncTask. So if you're going to go with making ImageViews without src in your XML, that's fine, but you can't just have the ImageViews go download their images via URL in the onCreate of your main activity any longer. It has to be done in the background, else you'll get an error.
It makes the process fairly more complex, to be honest, but it does improve application responsiveness.
For now, since images aren't the main focus of my app, I decided to just embed a webview in my page and then display the image in some custom html ( I had a list of URLs to the images online). I also calculate the width of the screen and then I adjust how wide the images are going to be in my html.
This was the easiest since the webview takes care of the "threaded" part and I don't have to worry about how to handle/save/and display the images.
It would have been helpful to see a best practices guide when it comes to android and handeling images.

Android displaying images in a gallery on main menu?

I want to create a main menu with a gallery that gets images from my website.
and shows them in the gallery for a user to scroll through and see upcoming event pictures.
The images will change just about every month. What is the best way to go about achieving this?
I was thinking maybe storing the images in a particular directory and having a URL set to the image.
The only question is... What happens when the images change? How would i go about updating the URL in the application? No way right?
Another thing... When the images are scrolled off the screen how do we make these images where they wont reload when out of view, causing unnecessary use of bandwidth and possibly outofmemory error.
So from what i have discovered so far, What is the best way a
You could store the urls in a database, have the app download a small text file upon launch containing the newest urls. if there is a difference, then download the new images and update the links in the database.

Categories

Resources