How to Solve Dex 65K Method Exception

While you gradually develop your application, you most probably would be encountered by the famous unable to execute dex exception.

 Conversion to Dalvik format failed:
Unable to execute dex: method ID not in [0, 0xffff]: 65536

or

 Conversion to Dalvik format failed:
Unable to execute dex: method ID not in [0, 0xffff]: 65536

You get this error mainly because there is a limitation on dalvik executable files and apparently the limit is 65536 which is 2^16 (two to the power sixteen).

This problem is also known as 65k method limit. So this limit is applied on the method count of your application. Android sdk methods are also counted. Therefore it is not that hard to reach out that limit. If you add a few third-party libraries to your gradle file and also android support libraries and google play services library, eventually you will hit the limit.

Continue reading How to Solve Dex 65K Method Exception

Anim Button – Inspired by Whatsapp

In some of the popular chat applications like whatsapp or hangouts, there is a button which can be transformed into a record button and also when you enter some text it will transform into a send button.

AnimButton is a custom ImageButton which is imitating the whatsapp’s send button behavior. Basically, it will change the image source when you enter some text on the edittext and it will go back when you clear the edittext

In this post I will try to mimic this behavior in my AnimButton project. Also, the full source code of the project can be found on the Github.

Continue reading Anim Button – Inspired by Whatsapp

SparseArray vs HashMap

Main purpose of SparseArray in Android development is to have a memory efficient integer to object mapping.

It is not solely about to gain a performance tweak, however, you will save much more memory by using SparseArray.

Benefits of SparseArray

  • Saves you memory (Less memory usage thanks to the primitive keys and no Entry objects)
  • No auto-boxing (Because the keys are primitives e.g. int vs Integer, it will not convert your key to a new Integer(key))
  • Less time spend in GC-Garbage Collection- (With auto boxing there will be redundant Integer and Entry objects in the memory which needs to be collected by GC after their usage end)

Continue reading SparseArray vs HashMap