OK so there are 2 concepts for Lazy Loading from all I have read.
Load images in a background thread.
Only display the image when the user is not interacting with the screen. (i.e. display it when the user have stopped scrolling)
My question would be, which one of those would be the right one.
For implementation, I'm using Universal Image Loader. Is it possible to implement concept #2 with this library natively, or should I add some extra code?
First off, you should know there isn't "right" or "wrong" one when it comes to user experience. It all depends on your way of thinking. However, based on Android guidelines, you should never perform heavy tasks on the main tread as it might affect user experience. It means you should always try to load images on a background thread.
But the question is whether you should keep loading and unloading the images as the user scrolls or you should only display the image once the user stops scrolling. I "personally" believe that the answer depends on the situation. For example imagine a your facebook friends list where there is names tags beside the images. In this case, you might not need to load all pictures as the user is able to search the list, scroll up and down and pick the right friend based on the name. However, if the user is expected to pick and select merely on the image. Then for sure the answer is to display the image once it is available.
Related
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
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
I'm new to android development and I want to create a navigation concept which is a little weird for android and not sure what is the best way to develop this.
In a nutshell the application hold an endless collection of images downloaded from the server as the collection processed with buffering to make it smoother.
The general Idea is that I see the image full screen and have the ability to either swipe left or right, each direction represent a different action on the image and will show a small image near the image during the swipe to indicate which action I selected. Afterwards regardless on which action I selected it will swipe to the next image in the collection.
What would be the best direction to solve this problem, PagerAdapte or FragmentStatePagerAdapter (since I don’t have the ability to navigate back to an image)? Manually implementing the swipe using listeners?
Also how do I deal with showing the small images without making the code too awkward?
Should I use Volley for the image downloading?
Your answer is Bitmapfun. Try implement it. First screen of this application is gridview. If you click one of those items those images are shown in ViewPager you have to implement the ViewPager section. It also cached those images as you mentioned in your question.
Github link
Here is my solution to your problem:
First use volley to download images because:
1- Volley is open source and you can easily configure it, the concept behind it is very simple.
(for example you can change cache size, thread pool size for network requests and so on)
2- Volley uses two level caches, so makes you feel free about memory and …
3- Volley decodes images for you on the worker thread and that’s another problem you may face it but Volley solves it for you.
4- Volley handle configuration changes so on the flight requests dose not duplicate if orientation changes and you request them again(for the first section)
5- You can ask volley to deliver you an image in a different sizes so your thumbnail image and real image all can be delivered with just changing the request image size
6- You can change the HttpStack of it to run on a OKHttp , which is more optimized for all version down to I think 2.2
All you need to do is just spend some time to understand it and configure it to get most performance from it and use it’s two level caches to show your slides.
For showing the images I do not recommend you any of FragmentPagerAdapter nor FragmentStatePagerAdapter because:
FragmentPagerAdapter is not suitable for large collection of fragments because it store all fragments in memory and you will soon get OOM exception.
FragmentStatePagerAdapter is good because it handles configuration changes but it also stores at minimum 3 pages in memory which one of them is the last page you just visited so because you do not want to go back to last image it wastes memory for you.
I think best solution is manually implementing the swipe using listeners with the idea of off screen loading, to load for example two next images in memory.
Have you tried AndroidImageSlider. It is open source and has some pretty awesome features.
you can refere this " https://github.com/Dreddik/AndroidTouchGallery " link hope it`ll helps u :)
I know this is a general question, but I don't know where to ask this. I was wondering what is a good design practice: to load data before creating an activity; or to create the activity, load the data and populate the UI.
In my opinion, fetching the data before isn't a good idea since you have to pass the information in a bundle to the next activity. Furthermore, you are handling information that is not relevant to the current activity. The only reason I see to do this is if you have a LOT of data to load and you don't want to stop the user from interacting with the app the time being.
However, I've seen a lot of people who load the information in an AsyncTask before launching the activity, even if it's a few bytes. Why? Is this the expected way to do it?
You can't give 1 perfect answer for this question as there is many different ways of doing this.
If you have something that is similar to a news app you'll be able to load content minus images while browsing a list and if the user goes to detail you could load the image on the fly and just display the text. But thats just one way of doing it. Some might prefer loading the image before displaying a detail screen.
My advice will be to think about your users and their work flow and you won't fail completely. And take this question on a case to case basis.
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.