Memory and performance are some of the key parameters which determine the success of any product and a mobile app in particular. Since Android supports multiple processes to run simultaneously, the memory constraint is even more in Android devices. Typically Android phones support 16MB per process. Here are some key areas to look out for when developing an Android application:-
--Always avoid using Reflection as it decreases performance. Reflection is usually used to change the runtime behavior .Reflection decreases performance as JVM optimization cannot be performed.
--Whenever possible use REST based web-service calls as against SOAP. SOAP based calls are least preferred for mobile devices. REST is more Light-weight and it also gives results in readable format.
--Go for SAX parser versus DOM, whenever you have a choice. DOM uses more memory and is slower compared to SAX. SAX does not to create a default Java object model on top of the XML document and hence increases performance and memory usage.
--Use weak reference and soft reference wherever necessary, especially when you know that some of your objects will eat up a lot of your application memory. You are guaranteed by the JVM that your Soft reference will be garbage collected before throwing OOM. Depending on your application needs you can decide which reference type to be used.
--Always display as much data that the user can actually see. If you have 1000s of records to display, do-not bring in more than 10 records at a time. That is design your application in such a way that only the items that are visible to the user at a time are brought over from the network from each network call. In this way you have decreased user-wait time as well as the battery.
--If you have images/bitmaps to display in your lists, implement scroll listeners and bring the images only when the user scrolls to view those images. This helps battery life. Use Bitmap.recycle() to free the memory.
--Use the hierarchy viewer to note the depth of your UI layout. As the depth of the layout decreases the performance increases.
--Use the layoutopt tool that helps you identify holes in your layout and thus increase performance.
You can also refer to the detailed documentation in the developer site for more information
Sunday, December 6, 2009
Subscribe to:
Post Comments (Atom)
1 comments:
You might want to investigate vtd-xml as a new and most powerful option for xml processing
http://vtd-xml.sf.net
Post a Comment