I have about two years of experience as an android developer and I have published nearly 3 apps on playstore. In this article i will share you some of the best practices that i learned on my journey as an android developer.
I have been through lot painful experiences and made lot of mistakes and i have learned from my mistakes. I hope sharing my experience will help you save your time and energy.
keep android studio updated
Android studio was not fully developed and it had lot of bugs. With each new version of android studio engineers at google are improving the IDE and fixing bugs and increasing performance. In my own experience as an android developer lot of times new version get fixes to one of the most annoying issues. Keeping android studio updated to a stable version can really save you a lot of your time.
Android Studio until now had a lot of issues and bug fixes. Official documentation for android studio tells that android studio version 2.3 is one of the best quality IDE till date. Which is released only recently.
Keep your gradle plugin and gradle updated
Gradle build system was very slow and one of the biggest bottleneck in the speed of android studio and building the software. Each new version of gradle and gradle plugin are offering improvments in performance and build time. Recently lot of improvements have been made and these days gradle has improved a lot. It has become more faster. Keep your gradle plugin and gradle version updated.
Always use a support library
Initially enginners at google planned to provide support library as something which is optional. But later as android platform grow google started pushing one of the best and most essential features exclusively to the support library. Which implies that google recommends using support library. It no longer considers support library as optional.
Officially google may not tell you but on an informal level everybody knows that you must be using the support library and its not optional but something which is mandatory part of android development.
Consider alternatives to Parcelling Objects
While developing on android we often face requirements where we have to pass objects from one activity to another. The officially recommended way of passing objects is to make your object implement parcelable interface.
You dont have to implement parcelable interface to pass objects from one activity to another and this approach has certain pitfalls. The non-primitive variables will not get parcelled unless they implement parcelable Interface. Timestamp’s do not get parcelled. There are fixes for parcelling timestamp and non-primitive objects but they get messy and complicated. An alternative to implement parcel interface is to encode objects into JSON String using GSON Converter and then pass the string with the intent to the another activity. On the receiver end you decode the JSON string into an actual Object. You may not understand this if you are not aware of JSON parcing and convertors. Dont worry in this situation. Try to learn about JSON Parsing first and then revisit this topic. This will help you gain a better understanding.
Always consider using a fragment even if you are using only a single fragment within an activity
Even if you have only one fragment in your activity you can still benefit from using a fragment. There are many benefits of using a fragment. Fragments make your code more reusable. It simplifies the development. Fragments even simplify and help you in dealing saving instance state while configuration change. You can use set retain instance option in fragment which can help you retain your instance variables. You can find out more about how fragments can retain instance variables at this link :
One of the reason why most of the developers refrain from using fragments is because they get confused about how to use fragments. But when you gain a better understanding on how to use fragments you will start to appreciate better why using a fragments is a best practice and it is a standard.
Tips and Tricks
Consider using a real device compared to an emulator
If you are profession android developer and working an a real world project it is always good to use a real android device for launching and testing your apps while developing instead of using an emulator. When you are developing on an emulator you miss out of lot of problems and issues which you may face later when you launch your app on a real device this happened with me when i developed an app using an emulator when i later discovered that there were lot of errors and bugs when i launched my app on a real device.
Emulator doesnt show you what exactly your app will behave on a real environment.
Use ADB over wifi
One of the biggest problems that android developers face while developing on a real android device is the need of connecting the device using a USB cable. The USB cable gets damaged usually after few months and then our connection to the device keeps failing.
One of the best alternatives to using an USB cable to connect your android device is to connect your device to your computer using a wi-fi connection. You no longer have to use USB cable and
Saving Instance State – Enable set retain instance which will help you in retaining instance state over a configuration change
Android developers face one very messy and ugly problem which is to save your instance state in order to recover from a configuration change. This problem can be simplified elegantly when you are using a fragment.
While using fragment enable set retain instance. This tells android not to destroy your fragment when configuration change happens and it therefore retains all the state of instance variables. More details about this is given at this link :
Prefer using contraint layout’s over Relative Layouts and Linear Layouts
Constraint layouts are a major improment over the previous layouts. It really simplifies the task of developing layouts. Its more powerful and also provide you a performance advantage. Therefore learn to use constraint layouts and prefer to use it over other layouts.
use progress bars where ever possible
Typically when you make a non-blocking call like a network call. The user must know that some task has been performed in the background. The more progress bars you use the better use experience your app provide
Make a blog and share your experience
Making a blog will help you more than it will help other people. On your journey of becoming an android developer you will learn lot of useful experience and tips and tricks. If you dont take notes of the useful things which you are learning most likely you will forget them later. Therefore maintaining a blog helps you take notes of what you are learning as a developer. In the future when you forget something you can refer to your blog which may help you remind the solution.
Your blog will help you take notes of what you are learning. Your blog will become your notebook for you which will help you to come back to revise what you have learned.
These days you can start your own wordpress blog in a dedicated hosting platform on just 5 $ per month. So making a blog is not a big deal.
Consider developing on a Linux or preferably on Ubuntu machine
These days cloud hosting skills and open source is gaining lot of demand in the software industry. Developers with cloud hosting skills will have high demand in the near future in the software industry. Most of the popular cloud hosting platforms like digital ocean and AWS use linux servers and therefore having good expertise on working on linux will give you an edge when you are working on cloud hosting platform.
Do not forget to install 64-bit packages if you are developing on Ubuntu
This is a very common situation that most of the developers face when you are beginning to start android development on Ubuntu. You have installed Ubuntu 64-bit but you dont have 64-bit packages installed which are required for running some of the android SDK components. As a result your android studio build will fail. The most frustruating thing about this issue is that nobody will tell you the reason and cause behind the problem you are facing. After doing a lot of careful good search you will realize the true reason behind the problem that you are facing.
In order to install 64-bit library packages please go on to this link https://developer.android.com/studio/install.html and choose linux. Here you will find instructions on how to install 64-bit libraries.
Consider using at least 16 GB ram on your development machine
I know most of you would say that even 8 GB should be sufficient. But as most us android developers i must tell you that we don’t use our computer just for running android-studio. We tend to multi task and you are very likely to search for a solution on the internet while coding and therefore eventually you may have 10-20 browser tabs open. This is when you start to feel that 8 GB ram is not sufficient for your needs as an android developer.
Consider Using an SSD over a conventional hard drive
Android studio and Gradle build system require a computer with a good performance. There is a huge performance difference between an SSD or a conventional hard drive. Once you have used an SSD you will never switch to a regular hard drive.
Good Internet Connection is required its not Optional
When i started my career as an android developer I used to work over a low speed internet connection. Gradle and android studio needs good internet Connection. Gradle and android studio will be downloading lot of updates from the internet and sometimes it will do it in the background. If you have a low-speed internet connection then you are going to feel very frustrated as a developer because in most of the cases gradle does not even tell you that it is waiting in order to download a file over the intenet.
Join a developer forum or a developer community
Join a Software Development forum where you can interact with professional android app developers and keep in touch with other developers