android studio IDE in which I wrote my First Android App

Few days ago I gave my source code of First Android App to tech section of SKDRDP as my computer broke up. The app I was building was for Cash Collection Tracking which will be used by Field Staff of SKDRDP. It was one heck of journey to build the first android app. This app building forced me to use many  of the core android features namely Activities, Services, and Content Providers. On top of that I was not a “professional coder” but a MBA who codes. Do read on how an app taught me coding.

The events leading to picking me up:

On one fine day in month of May I was approached by  staff of tech section asking whether I knew android application development. I replied them as yes but I am not a proficient developer as I did course long ago. Later they asked me to help them in building their app for cash collection. Technically they wanted me to port the app but I had to resort to building form scratch as that was much easier. Then we had tons of discussion how they had built the app for Nokia Platform, what all features they were expecting etc… I categorize this discussion as  “Requirements” Capture phase.

Understand the app’s requirements(what it is supposed to do?) correctly, that will avert costly reworks down the line.

After all the discussions were over, I asked them how they came to know about my skills in Android and they told me, that they found out using Google. I was bit astonished as My Name in Search Term wouldn’t have revealed Android aspects of me. I later came to my desk and checked various combinations of Keywords which would throw out my name in top search results. After trying for hours, I decided to key in the same term which I would search If I were looking out for developers, That is  – “android developer Dharmasthala”. Which would lead to me ruling the search results. Also my article on setting android IDE adds relevancy in the eyes of search engine. They went from search result to my blog to read this article How to set up Development Environment for Android? and later decided to contact me.android developer Dharmasthala - Google Search the thing that lead my First Android App

 

After I was on-boarded, they got permission of SKDRDP’s CEO to help them in building app as I report directly to him. Once the permission was obtained I got going. But the events that culminated in me doing the app rested on “bad events” shaping my past.

Dots of Past:

I did my Android App Development course soon after I finished my MBA somewhere in 2012. At that time majority of the budget phones were running Gingerbread 2.3.3 version of android. later I had to quit one of the job, But immediately after quitting I ordered some books that would change my path forever.

The above said books changed my path in programming forever. Design Patterns affirmed why I need to handle every thing via Interfaces only. Refactoring helped me in changing patterns to make code readable. Code complete is one which gave a big bird’s eye view of Software Construction landscape. Luckily Steve Jobs speech did help in affirming my gut feeling about ordering these books.

Apart from books there were much of learning from Unrelated courses done on sites likes Coursera, EdX, Udacity. One of the key features of these courses were on having our own coding style. If you see the code I have written  on github you can see glimpses of my coding style. The Code Complete also focuses on this.

Every Programmer is an Artist. Like every artist they have their Style etched into their works.

Role of Design Patterns and Code Complete 2 in My First Android App:

Some time after I did my course on android, I was introduced to “Design Patterns” book. I was so much immersed in this book, I even flunked in Google interview. Its because of this book I can appreciate why Java doesn’t support multiple inheritance for classes but allows the same for interfaces. Why there is clone() method attached to every java class. Also using the techniques like always pointing to the interface and serving requests to it.

Majority of problems in programming are at times repeating in nature. So chances are there for another programmer to encounter the same in past as well future. For that reason, the design patterns was written. The patterns were distilled by looking at various practical problems and how they were solved in past. The jUnit testing framework also depends on these patterns itself. By giving names to these patterns it becomes part of programmer’s lexicon.

Access a class through its interface only. Don’t break encapsulation.

If work can be accomplished by Object composition do it, don’t inherit.

The major role design patterns played was in preparing the interfaces. With stricter interfaces, it was easy to communicate with other parts of program. Database was abstracted into Content Providers. UI were segregated into their own package with DB operations abstracted. If activity had to communicate with adapter, it was enforced on usage of that adapter’s interface instead of direct access. The main advantage of this was in Code Readability.
Class structure of my First Android App

Code like boolean isMemberPresent = memberAdapter. isPresent( memberAtPosition ); is readable, isn’t it?

The other book that played a pivotal role in bringing the app to fruition was the Code Complete 2nd Edition. Its this book that cemented my style. In above code example if member at position was replaced with i, the code wouldn’t be that readable. The code complete has many more tips like that. Its based on the tips and techniques given in book my first android app could be completed instead of throwing my hands at first sign of trouble.

Refactoring and My First Android App:

The books of code complete and design patterns did provide me with a solid foundation in programming. It was refactoring that smoothed the rough edges of my skill and made things really manageable. Refactoring mean making small meaningful changes to program. Its the various refactorings that made code more readable.

refactoring grab

 

Earlier my logic in fragment swapping was embedded deeply in method in Fragment Class. Later I ran Extract Method refactoring to separate the fragment swapping into its own method. Once this was done I moved the method to activity as the job of managing fragments was supposed to be in Activity. Rename was used excessively as I preferred names which are easy to tell and contextual. The reason why I kept every thing simple was because I wrote the code which would be read by tech section. Also the ultimate responsibility of extending the app was resting on them, simple code was paramount.I also did some “Replace Inheritance with delegation” on my text watchers and on click listener classes. As I was moving them to my newly formed Adapter class. All these refactorings were done with purpose of keeping the encapsulation intact. Its because of these refactorings the code of my first android app is “Readable”.

How GitHub helped in versioning my First Android App:

Initially I disregarded importance of keeping the version control in place. I later did one code change and it broke the app completely. Luckily I was able to figure out that code change itself was buggy. Then I rolled back all the changes and immediate setup GitHub on my PC.

github

Once the version control was set up. I integrated my IDE with it. Its because of this I was able to write what all things I added to code in English. The naming convention for version numbers was 1.x was for major UI change. 1.x.x was for adding a small new feature. the 4th digit was for smaller fixes done to code. Also in code complete 2 there was mention of creating daily builds hence I committed all the changes I made at the end of the day..With each commit a build was created and tested. Due to faster commit and build cycle the debugging was considerably easier. The commits with D in names were builds which I had set up for debugging purposes. That code was littered with Log. d( "xxxx", "yyyyy" ) messages which kept pulse on everything happening in my program.

The main advantage of Version control was I could only concentrate at what all was changed and fix if the build was broken. This concentrated scope aided a lot in debugging. With each commits synced to GitHub at the end of they I was guarded against my PC breaking up, which it did when I finished the app.

This was my journey of writing first android app. Do share your views and first android app experience in comments.