Activities loading slowly in app - android

I have created an app that gives a lot of imformation on various topics and stuff. My app has a lot of images and all are between 200 and 290KB (jpg). I have a Sliding drawer with Imagebuttons (around 41 ImageButons). When selecting the category (For example going from the main menu to the information Activity) with these ImageButtons it takes about 2 seconds to load. However when selecting a imagebutton it displays the image almost instantly. Is there a way of speeding up the loading process going from the main menu to the information Activity?

around 41 ImageButons
do you really need 41 image buttons? Cannot it be something smarter (like regular button with the same drawable as background so it looks like image button and is not and does not required 41 images to be opened, decoded and used? Also using PNG instead of JPEG could improve this. But in general, rethink your UI

You must load your image asynchronously: the interface loads immediately, but the image processing tasks are done in parallel and your images will appear progressively.
Basically, you must use AsyncTask. The developer portal provides a great tutorial with a downloadable and usable code sample.
http://developer.android.com/training/displaying-bitmaps/index.html

One question: What is your Sliding Drawer for? How many buttons are visible at once? If you just display a few at once and slide through all others via a "right-to-left" swipe then you really should use a ViewPager (introduced in api-level 13 I think and available through the support library for every api-level above 4).
What it does: It just loads the ImageButtons that are visible (much like a ListView does), so there would be no need for one layout with 41 ImageButtons. You just design a Fragment that gets dynamically the different image buttons. Check the documentation for more information: Link

Related

Android implementation of tutorial screen

I'm planning to implement tutorial screen for Android app.
My plan is that tutorial screen looks like:
There are several screens and you can swipe between than. Every view has custom design. There are dots which represents every screen, and show what page are you watching now. I need good-looking transition with adequate animations.
This screen will be full screen activity.
I have found several Image Galery, but I don't want to slide between images, I need to slide between views.
I do not need exactly code for this. I need instruction in which way this can be done, and what elements I need to use in order to achieve targeted design.
Thanks in advance.
You'll want to use ViewPager in conjunction with Fragments, the instructions are on Android developer's website.

how to load a layout in background?

I have a layout in my app that has lots of images, buttons and other layout elements.
The first time the user starts the activity of that layout, it causes the app to freeze for 1 second.
I want to load the heavy layout elements in my splash screen, so that when the user starts that for the first time there is no freezing.
How could I go about adding this feature into my app?
First load all the UI elements and then try to load the images in your respective layout.
Loading the images can be long process, so use async task for that.
For loading the images efficiently you can use the following code shared by Google. Below is the link for that...
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
You should probably look into AsyncTask Handler. It will also allow you to easily support progressbar.
In case if you have a lot of images to load, you can use image loading libraries refer this link for more Image Loading Library. These libraries load images in background and provides many more options to deal with images.

Newbie in Android development. Implement several different processes in an activity

I'm begining to learn android development, and I'm trying to make an app just to learn the language and philosophy.
This app, has to show an image in the middle of the screen, a button below, and a chronometer in the right side. When the app starts, the chronometer has to begin a countdown. When the user press the button, a blur effect has to be applied to the image, and the seconds left to finish the countdown increase by 10.
I almost know how to program the blur efect to the image, the button press, and the countdown and increase by 10 whenever the button is pressed. But I'm not sure about putting all together.
As far as I know, it should be done by designing an activity, and putting inside the activity the image, the button, and another image or a set of changing images or text for the countdown clock. But as I advance in my studied, today I have read that in order to manage different actions in an activity it is neccesary to do it by using fragments. And I have found much complex programming fragments than activities.
So the question is: can I make what I'm trying to do by a simple activity and defining classes and methods for the image effect and the countdown clock or have I to make it with fragments?
Thank you very much.
today I have read that in order to manage different actions in an activity it is neccesary to do it by using fragments
To be blunt, either you either misunderstood what you read, or you are reading the wrong material.
can I make what I'm trying to do by a simple activity and defining classes and methods for the image effect and the countdown clock
Yes.
have I to make it with fragments?
No. It is possible that the whole UI might be a fragment, particularly if it might be shown alongside something else in some cases (e.g., a tablet) and not in others (e.g., a phone). And there is nothing stopping you from making that UI using several fragments, though that would be rather unusual.
As others have already conveyed, no need to go with fragments.. Activity wud suffice.. As far as putting it together is considered, I guess you need to learn more about layouts.. Layouts are the files which basically help you put things on UI as you want it to look like.. There are plenty of material available online for understanding layouts.. Happy learning.. :)

What is a good approach to Flip through many (over 40) images?

Ive looked into the ViewFlipper, but defining 40 different views in one XML doc just doesn't seem like a bright idea. I know there has to be a better way, I just don't know how. I have spent some time trying to find a answer with no good answer so far.
I have used the Gallery widget (admittedly quite heavily modified) to display 200 fullscreen images in an image viewer for a client.
Alternatively you could use a ViewAimator with either 2 (in this case ViewFlipper) or 3 views (3 if you want to preload both the next and previous images). If you go for this approach then Laurence beat me to suggesting this idea ;) However I'd add that you would want to extend the ViewAnimator/ViewFlipper class to allow it to accept some type of Adapter.
A simple approach would be to simply contain two ImageViews within the ViewFlipper. Then when you request the next or previous view, set the new image resource for the next view and flip.
If you implement a lazy loader using AsyncTask or a Handler this will stop your UI thread from blocking.
Hope this helps!
You could use a ViewPager (included in the Android compatibility library if you need to support pre-Honeycomb devices).

How to Have multiple buttons inside Android SlidingDrawer Control

I am making a quiz application in which i am planning to use the SlidingDrawer control for displaying different question numbers. Clicking on a number will allow the user to jump to a specific question.
I have implemented the sliding drawer control but it is able to display only 6-7 buttons inside it depending on the screen size. Trying to add more buttons to it gives an exception.
I tried using a GridView inside the SlidingDrawer but i keep getting an error.
Is there anyway i can have around 20-30 buttons inside the SlidingDrawer control arranged in a grid like manner ?
Please give suggestions on any other way i can implement similar functionality in a way that doesn't take up much screen space ?
Yes, it's possible, as a matter of fact previous Android versions (1.6 if I'm not wrong) implemented the application Launcher that way.
Search the source for that version and you'll have a working sample.

Categories

Resources