I am building a simple photo sharing application. When I click camera icon, user would be able to take photo using the camera app. And when he saves that photo, it will be shown in grid view including the previously taken photos.
This means, when I take nth photo in an album , i should draw the bitmap for the other (n-1) bitmaps again. This would happen continuously. Even if i delete a pic, i should redraw (n-1) pictures using bitmaps again.
I am thinking of using some caching of created bitmaps and using it again.
Is there any caching recommendation for this scenario.
Thanking you in advance..
Regards,
Mugil
Here's a good place to cache icons: make a subclass of Application.
"Application" sticks around for the life of your application, regardless of which activities come and go. Even if you exit the app and do something else for a while, the app isn't necessarily terminated.
In your subclass, create your hash, array, or whatever to hold your icons.
Related
This question is a bit on the broader side of things so I will not provide any specific code because it will be irrelevant.
I have an app that allows the user to take photos, and hopefully videos in the future. Currently it happens as follows:
The user opens a dialog inside one activity.
The user can choose to take an image, which sends him to a CameraActivity (using CameraX).
The user takes an image, the image is saved locally in the app files and the result code and path to the image are sent to the calling activity.
The dialog overrides onActivityResult and loads the image from the internal storage and displays it.
The user can choose to delete the image or cancel the entire dialog, on both cases the image needs to be removed from the storage.
(The process can happen with multiple images inside the same dialog)
I wanted to ask you if it seems like a reasonable implementation or there are other architectures\android components you would recommend using. More specifically I'm worrying about the time it takes to save the image locally if I will want to increase the quality or do the same process with videos which are much heavier (I've already seen a considerable extra time if I want to save it as png instead of jpeg).
The two improvements to the system that I can think of:
Using something akin to ViewModel for saving the bitmap and having the data available when moving back to the dialog from the camera activity.
Saving the data to the cache instead on the local storage (and only save it to the local storage if the user approves in the dialog).
But I'd like to hear suggestions, are there any particular APIs that I should know about? or a recommended change to the architecture?
The current system will simply be too slow for higher quality images or a video, and I'm not sure how best to improve things and also not make the app too consuming on the resources side.
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 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.
I'm having trouble saving an image to my app. I have a button in an Activity that open up my gallery. I select a picture and that picture displays on screen in an imageView. Everything is fine as long as I stay on that screen. When I change screens and go back the image is gone. How do I go about getting that image to stay? (The image will be used as a "profile pic/avatar" that the user can choose themselves using an image from the gallery). **First time posting on stack overflow..sorry if I did anything wrong.
Each time your Activity goes out of screen, it will be stopped and may get destroyed. So each time you return to your activity, there is a chance that it get re-started from the beginning. That means your onCreate() method is being called(most likely) again. You can learn about Android Activity Life Cycle here. http://developer.android.com/training/basics/activity-lifecycle/index.html
Applications in android doesn't work in the same way as you expect in desktop operating system. Your Activity can get destroyed at any time or your Activity can be called to display at anytime.
Of course you can save information about the image chosen by the user last time. But you need to be aware of Android Activity life cycles first.
In fact you can save information of user's choice and load it next time the Activity is created.
If you want to make sure that your activity can display the image even after it is moved or deleted, then you can copy it to a Cache folder or store it inside SQLite database(though storing images in SQlite database is not recommended). Instead of cacheing the actual image, you may create a low resolution version of it using BitmapFactory class.
Android-Universal-Image-Loader library worth a look https://github.com/nostra13/Android-Universal-Image-Loader.
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.