Android Performance in Practice

I recently wrote an article explaining how to track down and fix performance issues in Android application. This article was by no means a complete reference on how to solve all performance issues and focused on a particular set of issues caused by overdraw.

To help you better understand how to fix overdraw issues, I would like to invite you to download a small Android application I wrote (click File > Download to download the entire archieve.)

Your goal will be to use the tools described in my previous article to find and fix the 3 main overdraw issues in the app. If you do it right, you should turn the image on the left to the image on the right:

16 Responses to “Android Performance in Practice”

  1. Gamma says:

    Thanks for the previous post, and the practical training !

  2. Marcus Körner says:

    I guess the most tricky part is to cut out the nine-patch drawable ;)

  3. Swaminatha Prabhu says:

    I have a question. Our team used to strictly obey the Lint warnings. The recent Lint enhancements are awesome.
    For your project, the lint warning reported as below for the file activity_main.xml

    Possible overdraw: Root element paints background @color/dark_background with a theme that also paints a background (inferred theme is @style/AppTheme)

    Going by the above suggestion we achieved the right side image. Now my question(confused), for finding the overdraw which one you suggest?? Lint or the debug methodology you suggested.

  4. [...] Afin de vous entrainer à éviter l’effet d’overdraw (redessiner plusieurs fois un composant inutilement), Romain Guy propose un projet d’exemple. [...]

  5. Afzal says:

    Hmm…after I finished fixing the 9-patch and set background drawable to null, my ActionBar background had no colour and the text + icon were blue, instead of green. :)

    Thanks for this exercise Romain

  6. is anyone else having a problem with “getWindow().setBackgroundDrawable(null);” having no effect to the overdraw? It works fine when it’s in the theme but not programmatically in onCreate()

  7. T says:

    Any response to the problem reported about setting windowbackground to @null causing “smearing”? See: http://stackoverflow.com/questions/12150761

    Afraid to try it because of that bug report.

  8. amor egypt says:

    could you talk about building custom list view from scratch with a high performance

  9. amor egypt says:

    could you talk about building custom list view from scratch with a high performance

  10. Afzal says:

    @Josh, I didn’t have a problem with that.

  11. Josh says:

    @Afzal/Anyone, hmmm. I see no difference at all. Do you? getWindow().setBackgroundDrawable(null) seems to have has no affect on overdraw. Sample is below.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setBackgroundDrawable(null);
    setContentView(R.layout.main);
    }

    and main.xml is just 2 view containers.

  12. Josh says:

    WP is stripping out the xml… the xml for main.xml is just 2 containers both have a background color. The inner once has 20 dp padding on the left and right so you can see the overdraw layers.

  13. Romain Guy says:

    Call setBackgroundDrawable(null) after setContentView() and see if it helps.

  14. [...] is a really good explanation how can you optimize your UI so it can load faster : Android Performance in Practice by Romain Guy. I suggest you to take a [...]

  15. ursus says:

    Will there be a solution published?

  16. he.cao says:

    replace @drawable/frame to @drawable/frame_hole in layout/photo_item.xml will do most of the work.

Leave a Reply