Imageview down the performance of my app - android

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

Related

How to use an asset in Android Ui?

I am new to Android Studio. While working on front end its sometimes easy to take some parts as png file and place it on the particular position instead of recreating it in xml file. I am confused can we use png all the time ? I am worried about memory space . Like the app contains 50 pages and in each page I use 1-2 assets . I don't want my app to have more than 40mb. What will be the best way to do? Can we store the image as a URL and retrieve it whenever we use. What's the drawback in that way?
So many questions :)
I am confused can we use png all the time ?
Use what's best for your picture. For a photo, a JPEG will probably do better. But if you wish, you can use PNG all the time, yes.
I don't want my app to have more than 40mb.
Check and see. Depends on how big your images are; we can't tell.
What will be the best way to do?
Not enough information to tell you that. In general, there's nothing wrong with using images in assets.
Can we store the image as a URL and retrieve it whenever we use.
Yes.
What's the drawback in that way?
You'll need to get some server space somewhere. Also, there will be a loading latency. Also, your app won't be usable while disconnected from the Internet.
While working on front end its sometimes easy to take some parts as png file and place it on the particular position instead of recreating it in xml file.
That's the part that is confusing to me. Android XML layouts usually contain interactive elements, ones that the user can interact with. Images, on the other hand, tend to be static. What kind of XML is there out there that you think you can replace by an image?

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

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

Rendering large images in WebView

I'm a newcomer in development of android apps. But, I'm undertaking what feels like a large project and I'm looking for information on whether it will work or not, before I get to far in.
As I've read, when trying to display very large images in android, it is most useful to use the "webview".
So, I took that advice, split my image into 1024 smaller images, and laid them out in an html table (not quite finished yet). Now, I'm noticing as the table gets larger my phone begins to lag upon scrolling.
My question is, is webview trying to render every single picture at once upon loading? If so, is there a way to make webview only render a set of images at one time? Let's say I'm at 14,000X x 24,000Y on the image, can I set webview to render the next 5,000px in each direction only, or is this necessary at all?
I can't seem to find the information I'm looking for, but will continue to search. Otherwise, any and all help is appreciated. Thanks!
i have exactly same problem and i found use full this library:
https://github.com/nostra13/Android-Universal-Image-Loader
you can configure a lot of parameters and using cache..

Best Way to Animate images frame by frame in Android

I have 3 sets of 50 images and I have to create the animations for each set of images in Android application. I am able to create a simple application which animate first set of 50 images using the below method,
Added Animation-list xml in drawable folder and called it using frameAnimation.start().
This method didn't work until I kept the following "android:largeHeap="true" in manifest file.
I am not sure whether this is the good way to animate the images (if we have more number of images and each image of more size like 60 KB. Image is JPG format) or not
I browsed and I found that, if we are able to clear the memory and if we are able to maintain less number of images in memory, then our application will work very fine. So I want to know how to clear the memory?
Please let me know do I need to follow different method to animate the images other than I explained above, so that I can clear the memory.
Thanks for your help.
After looking into several posts and doing much research, I finally ended up modifying the images in Imageview programmatically to simulate frame animation. That way I am just maintaining three images in cache at any point of time (previous, current and next one). I hope that this will be useful to others.
It is not a good thing to process a large amount of images in a frame like manner in Android itself as it will trigger the dreaded "Out of Memory" exception.
Clearing the memory itself is not possible. The best fix for this is proper bitmap handling of the app.
I'm not sure but you might want to check on PhoneGap.
Its an HTML5 Engine that we used before to create a game.
By drawing into the canvas itself, we've recreated frame animation with it. It just requires WebDev skills though.

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.

Categories

Resources