views:

110

answers:

3

Hello,

I want to do optimization of my android application.

Can anyone please tell what are different ways to optimize code and performance in android?

I gone through one tool i.e. Zipalign: an Easy Optimization.

Any other tools avaliable?

Thank you.

+4  A: 

There's no easy tool that just magically makes your app faster (zipalign just improves loading times). You'll need to learn how to write performant code. The SDK has some useful tips: http://developer.android.com/guide/practices/design/performance.html

If you have some CPU-intensive heavy lifting, you can rewrite that with the NDK.

Keep in mind that optimizing code will take time and can introduce bugs. Be sure to profile your code, find bottlenecks, and focus on getting those fast.

EboMike
@EboMike- Thanks for your suggestions. I will go through my code and link that you have provided.
krunal shah
In most cases, you can do without the NDK - it's possible to write fast and safe code in Java - just go through the link I sent. Most importantly, avoid allocations, and put slow computations into a worker thread. Only if you have some extremely complex calculations, you could consider the NDK.
EboMike
Thanks EboMike. I am refering the link you specified. And My application is very simple and dont have much calculations.
krunal shah
Good news then. You won't need the NDK. Just add timers to your functions that run in the UI thread and might take a while, and collect some data to see how long things take. Make sure the UI thread stays lightning fast.
EboMike
+2  A: 

Best practices are typically kinda obvious. Your application is most likely going to have specific unique bottlenecks. Check the android logs while your phone checks (Set a filter up) as the application runs. Check when the operating system is calling the garbage collector and how much information its removing.

If you are loading any files into memory be aware that android places (At least used to) a limit on the max size a file is (4mb) that can be loaded into memory.

What type of sensors are you using, if any... and if so in what way and is there a better way you can be using said sensors.

Are you storing to much / to little state in the application lifecycle steps.

steve
Hello steve, I dont know how to put a filter to check logs while application runs. And in my current application i am not using any sensor. And also not storing any state of application.
krunal shah
Sorry the filter is eclipse specific. Have you tried using the debugger? I'm assuming you are using eclipse :) (Sorry if you arent!... check the ddms - http://developer.android.com/guide/developing/tools/ddms.html
steve
Ya i am using eclipse only, and tried to use debugger also but dont understand much in debugger that how it works.
krunal shah
Ok well its very important to learn how to use the debugger for a number of reasons. When you have a strange problem a debugger is invaluable! :) To get started, just click on the line number in eclipse in a class that does something. Then when you goto run the application, pick the debug application tab instead. When the application arrives at where you have put the breakpoint your debugger will begin. You will be able to see just about everything that is happening in your application and on your phone! Its very important to know how to use this :)
steve
krunal shah
There is Traceview: A Graphical Log Viewer http://developer.android.com/intl/de/guide/developing/tools/traceview.html
Pentium10
You'll have to become familiar with the different types of messages coming from android. Some are just general information (Such as a sensor is listening for data) others are application specific, such as a google application saying its operating in the background. Eventually you come across garbage collection messages, its essentially the compiler saying that its recalimed some memory. I don't have the android on me now so I can't give a specific example, but at the very least become familiar with the debugger and log tab.
steve
A: 

Don't forget to remove all logging in the market version. Logging is expensive and the market only returns exceptions. Logging is mostly unnecessary and should only be used while developing...

WarrenFaith