banner-1165973_960_720

I realized quite lately the remarkable tool which is embedded with Android Studio – Analyze code. Behind the scenes, as anyone can see, Lint is the real tool used in collecting information.As one of our applications has several layers which were added  over time, the engineers working on the code left a lot of loose ends. I will give you some examples which are important.

  • Security section
    • AlowBackup/Fullbackup Content Problems : in the application section is better to signal if your application can be backed-up/restored by the system. In our case the Backup/Restore is a in-app purchase feature for all apps.
  • Performance section
    • Overdraw: painting regions more than once : we had encountered it many times
    • Unused resources: sometimes the old icons are carried through many versions. Be aware that sometimes the “unused” resources might be “activated” by branches of your code.
    • Node can be replaced by a TextView with compound drawables
    • Static Field Leaks :memory leaks with context placed in static fields
    • Nested weights are bad for performance
  • Probable bugs: this is the one which could lead to real problems. We comb through it and try to minimize the the umber of recorded issues. Example of  reporting:
    • Number comparison using ‘==’ instead of equals (comparing objects with numbers)
    • unused assignment – these could be bomb ticking especially for old code
  • Threading issues
    • synchronization on non-final fields: in our case was about back-up and restore of the database without locking it properly
  • Frivolous issues :
    • unnecessary semicolon
    • modifier ‘public’ is redundant for interface methods
  • Control flow issues: this section we call it refactoring and learning (for junior programming)
    • we like the ternary  conditional operator (maybe too much) like
      • from
        res = (!folder.exists()) ?
                    folder.mkdir() :
                       true ;

        to

        res = folder.exists() || folder.mkdir();

The nice part is that on the left side of the Inspection screen you have an explanation and as well the automatic fix if you don’t do it manually. As long as you understand and go through issues I hope that (at least) before beta release to use the Analyze code.

Categories: androidmobile apps