Showing posts with label best development practices. Show all posts
Showing posts with label best development practices. Show all posts

Thursday, January 26, 2017

Android Application best performance improvement tips

Recently I got chance to work on ongoing project. which means I had to continue working on code written by other developers. so I had to understand code so I can start working on my part.
After looking at code I realized that code is poorly written and it has several performance related issues in layout files and java classes. so I started making list of all issues I noticed in Code so I can share with other developers(already working on project) and we can improve our Android Application.
Some friends/colleagues asked me how you were able to identify so many issues in code so I though I will write an article on this.
Some points which I shared with other members in first code review.
  • Application shared preferences need to be singleton (Currently creating new objects every time in each class)
  • Fire base analytics need to be initialized once. (same as above)
  • supportsRtl was set to false in manifest file (They had to add support for Right to left layouts,But they added static files for each language. 1 file for English, 1 layout file for Arabic)
  • Use of inner classes for AsyncTask
  • No exception Handling
  • No run time checks with implicit Intents
  • Too many static Application objects.

You can study further why above mentioned points are bad practices/discouraged.
After above phase I noticed that some layouts are taking time while rendering even without any network call. surely performance issue agree ? Than I decided that I have to identify more issues in code and have to improve Application.
Than I started working on memory monitoring using:
  • Android studio memory profiling (Heap Dump)
  • Leak Canary
And identified activities which are leaking memory. and shared my findings with team members so they can also learn and not repeat these mistakes in future.
I am sure still there are many performance issues in Application, so I decided to take advantage of Lint.
Go to Toolbar in Android Studio and Under Analyze section click Inspect Code.
I am still looking for performance issues in our Application because I want to make it best Application. Still I have not started working on my part. fixing issues in code :)
Than I installed a plugin “Find Bugs-IDEA” in Android studio and analyzed code using Find Bugs. this is how its result looks like.
After fixing all of the above issues plus memory leaks. I am now confident that we have followed standards to some extent and our code is much optimized now.
Happy Coding :)
Please ignore Grammar and Punctuation mistakes. English is not my native language :)
Hammad Tariq
Android Developer

Kotlin Android MVP Dagger 2 Retrofit Tutorial

http://developine.com/building-android-mvp-app-in-kotlin-using-dagger-retrofit/