How to detect activity freeze & lag cause in android?


One of my activities is freezing and lagging a lot. I tried using profiler but couldn’t get much details. Is there any other tool that can help me figure out the cause for the lagging of the activity?

PS – there is a ton of flows and code in activity so no point in posting the code here


I think you have 2 reasons for lagging:

  1. You are very often redraw difficult UI in ViewGroup or RecyclerView. In developer options you can enable Show layout bounds for inspect this problem.
  2. You make something long in main thread and need to research what can long works in main thread.

Also if your lagging depends with RecyclerView, you need to make simple ViewHolder (make simple UI with one ViewGroup and remove all logic from ViewHolder, for example: string formatting, some math…). Also better to use ListAdapter instead of RecyclerViewAdapter.

Maybe if you will provide more info, I can provide you more recomendations.

Answered By – Andrii Hridin

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published