12

I am using Drawable.getConstantState to compare two drawables as mentioned here but couldnt understand its purpose. In the docs, its given that

Return a Drawable.ConstantState instance that holds the shared state of this Drawable

Which shared state?

Also, Drawable.ConstantState

is used by Drawables to store shared constant state and data between Drawables

So i dont understand which shared state here and what data is stored? And how does it help in comparing the drawables.

Community
  • 1
  • 1
Diffy
  • 2,339
  • 3
  • 25
  • 47
  • 4
    read this: http://android-developers.blogspot.com/2009/05/drawable-mutations.html?m=1 – pskink Aug 30 '14 at 07:27
  • @pskink thanks for the link.When we create 2 buttons, a different instance of drawable is created each time, so memory is being used here. How does sharing a common state between them saves memory? – Diffy Aug 30 '14 at 07:36
  • ok, buttons by default use NinePatchDrawable by default and this Drawable, in order to draw itself, uses NinePatch object, this object is relatively big as it holds a bitmap that will be drawn, and even each Button's Drawable is a different NiniePatchDrawable but all of them point to the same NinePatch object – pskink Aug 30 '14 at 08:00
  • @pskink you saved my day.. you saved 2 of my days – PrashanD Jan 10 '19 at 04:53

0 Answers0