The impact of not following the best practices

One of the recommendations we have been giving during these last chapters is to avoid allocating objects in the onDraw() method. But what will happen if we start allocating objects?

Let's create a simple custom view and allocate an object on purpose so we can evaluate the result when running the app:

package com.packt.rrafols.draw; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; import android.graphics.Region; import android.util.AttributeSet; import android.view.GestureDetector; import android.view.MotionEvent; import ...

Get Building Android UIs with Custom Views now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.