Do’s and Don’ts for Beginner Android Developers

In last couple years, there has been increasing demand for Mobile application developers in software industry, specially Android and IOS, so naturally many developers are trying their hand in same. Android, holding the biggest market share in mobile market, is the favorite choice for many developers. Being Android Beginner Developers myself since last year, I have committed many mistakes which I shouldn’t have and would like to share some do’s and don’ts for Beginner Android Developers.

Do not develop application for your device.This is the common mistake by many Beginner Android Developers either because of noobness or unavailability of mobile devices for testing. Android is widespread market with variety of devices, with variety of Android flavors. As of writing this, google developer console shows around 14k devices (actually number will be more than this) in Device Catalog.Do develop your application keeping in mind all those devices and try to provide consistent app performance across the same. Make sure code and xmls written by you works across all the devices by testing your application on wide variety of devices. You can use Android emulator embedded in Android Studio for the same. If you feel, emulator is too slow for you, you can always use Genymotion Android Emulator. It is free for personal use and super fast!

Do’s and Don’ts for Beginner Android Developers

Do not try to create “Do-it-all” application and use Intents specially if you are Beginner Android Developers.
Follow KISS (Keep it simple, silly) principle while writing code.
For e.g. suppose you want to send text message from your application, you have 2 choices. You can use SmsManager, for which code goes something like this,

Same can be applied for clicking pictures from camera app, picking pictures from gallery app etc.

Do’s and Don’ts for Beginner Android Developers

Do not fill up your code base with activities.Activity transitions are expensive as the old activity as to be destroyed/paused/stopped, pushed onto the stack and then the new activity has to be created/started/resumed. Plus more activities means more complex manifest file.Do use fragments wherever possible because of advantages like
– Fragments are Android’s solution to creating reusable user interfaces.
– The FragmentManager handles «back» for you in a very clever way. Back does not mean back to the last activity, like for regular activities. It means back to the previous fragment state.
– You can use the cool ViewPager with a FragmentPagerAdapter to create swipe interfaces. The FragmentPagerAdapter code is much cleaner than a regular adapter, and it controls instantiations of the individual fragments.
– Your life will be a lot easier if you use Fragments when you try to create applications for both phones and tablets.
– Fragments are independent components and applying animations on them to create cool UI is comparatively easy.

Do not use hard coded strings in code.One of the most important Don’t in Android Development and done by most of the Beginner Android Developers. Using hard coded string all over your code base in nightmare and has potential of wasting your precious time in future in finding those strings in code for any changes.Do use strings.xml for storing all the strings, even simple strings like “Okay”. It is whole lot of easier to make changes quickly in text of app in strings.xml rather than going in code. Plus it makes it easier to convert your app to multiple languages in future.

Do not write spaghetti codeWriting spaghetti code is easier but maintaining such code is worst nightmare for all. Specially if you are not the one who is going to maintain it!Do follow coding guidelines, apply best suitable model of software design wherever applicable and always make sure your app is maintainable, robust and testable along the way. You can refer to series of articles I have written for writing code with Great Android App Architecture.

Do not write boiler plate code and reinvent the wheel.From wiki, In computer programming, boilerplate code or boilerplate refers to sections of code that have to be included in many places with little or no alteration. So in your early days, you would have been using findViewById to bind view to instance variable something like this.

View view = findViewById(R.id.someView);

Now imagine if you have tens of such views to bind! Its nightmare and waste of time to write this.

Do use library Butterknife to make your life easier instead. Similarly there are hundreds of such libraries out there for reducing boiler plate code and improving your development speed. For e.g. Retrofit, Glide, Material Dialogs. Keep exploring!

Do not just use Android Studio as code editor and debuggerMany a times, beginners will keep using Android studio only as editor and debugger without knowing all the cool stuff you can do with it to speed up development.Do use all the cool features it has to offer like split screen editor, distraction free mode, live templates (writing toast code in second for e.g), overriding super class methods by shortcut and many such. Refer to this link and this link for more.

Do not just copy code from SO or GitHubWell who doesn’t do this? But it is recommended not to do this. You have to print some bundle object in log with all the key value pairs, you go to google, search, open first SO link, copy first answer, paste and see it working. Cool, what’s the problem in this? It may seem easy to do so but you do not really understand what you did there and when tomorrow you have do print bundle again, you need to follow same old process. Imagine had you written code by yourself instead of copying, wouldn’t it be better for your understanding?Do understand what you are doing instead of just copying and pasting code from SO and GitHub. Rewrite if you will. As per your need.

Do not just use Gradle for building apksGradle is an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. It has so many more features to offer other than just building your damn apk like configuring build types, product flavors, Build variants, Pro-guard support, Multiple apk support.Do understand Gradle build system and try to use it at its maximum potential. More reading here.

Do not think about premature optimizationsThey say premature optimizations is root of all evil. Do not do it. Well in my case, in my beginning days, I always used to think about extra time needed in all the null checks happening in my code, little I know how stupid I was being, focusing on optimizing single if-else statements rather than at places where it actually matters like DB operations, network and file operations.Do focus on getting your code working first, optimizations come second!

Do not just catch exceptions and do nothing about it for the sake of avoiding crashesIt will cause your app to behave abnormally without giving you any clue of what went wrong. For starters, this is the piece of code I am talking about.

try{
some code here
} catch (Exception ignored){}

Do perform some action when exception is caught. They are caught for some reason.

Do not be static HTML in world of PHP, JS and whatnotAndroid (or any kind of technology for that matter) is evolving in fast pace mode and it is necessary to keep yourself updates with latest tools, tips and tricks to not fall behind.Do reserve some of your time for following all the official android blogs, famous android websites and YouTube channels for keeping yourself updated in the field.

Last but not least, do not ask your questions and doubts at wrong places.I mean what is the deal about asking your coding problems on Quora, YouTube comments or some articles comments for crying out loud, use proper channels!If you think I missed some, mention in comments and subscribe for some more cool content coming up!

[…] to get job in 2018 How to download Subtitles for your movies and series in one click for Windows Do’s and Don’ts for Beginner Android Developers Migrating existing SQLite implementation to Room How to store Java Objects in Room Database? […]

*I discovered your blog site on google and check a few of your early posts. Continue to keep up the very good operate. I just additional up your RSS feed to my MSN News Reader. Seeking forward to reading more from you later on!?

I simply want to tell you that I am just all new to blogging and site-building and really loved this blog. Most likely I’m planning to bookmark your blog post . You certainly come with very good writings. Appreciate it for sharing with us your blog site.

I simply want to tell you that I am new to blogging and site-building and certainly savored your web-site. Very likely I’m planning to bookmark your site . You actually come with superb stories. Thank you for sharing your web-site.