How to Become an Android Developer in Less Than a Year

The title got your attention didn’t it? Now don’t worry, this isn’t clickbait. In the following article I am going to tell you everything you need to know about what it takes to become a professional Android developer. However, don’t assume accomplishing this will be easy – it is going to take a lot of work. Achieving this quickly is going to require dedication and a strict routine. In my opinion, you will need to set aside 2 – 4 hours a day, at least 5 days a week, to studying. For 99.9% of people – this is completely doable. Also, if you have intermediate programming knowledge, this can be done in 6 months or less. Before we get in to discussing exactly what you need to study, I’m going to elaborate on how you should study Android development.   When should I study? Whenever you can set aside a solid window of time. For most people in school or those with a full-time job, the best time would be in the evening. In the case of students, just dedicate at least 2 hours a day on top of your normal studies. Do not be tempted to go out and get wasted on the weekend, or even worse, during the week. You have little to gain and a lot to lose by engaging in this behavior – I’ve been there and it’s not worth it. For those with a fulltime job – I know this can be extremely difficult. By the time you get home from work you are probably already exhausted. This feeling can be exacerbated if you are working a job you don’t like. On top of this, you need to make dinner and wash the dishes (if you are not blessed by the holy invention known as the dishwasher). I feel your pain. However, …

Time & Space Complexity in Functions – Big O Notation

Knowing how fast a function will run or how much memory it will require when running are important factors to consider when writing algorithms. This may not be something to consider in small, simple programs, but just imagine a large project riddled with unoptimized and slow performing functions. It can have a drastic impact on overall system performance. Luckily, there is big O notation, which allows for quick deduction as to how fast a function will perform or how much memory it will require. Introducing, Big O Notation Big O notation (also known as asymptotic notation) is simply a mathematical notation we can use to measure the performance of a function. There is no math involved in this approach, rather you only need to look at the code in order to classify it. The main way we go about achieving this is by determining how fast the runtime will grow in relation to the size of the given input. For example, some functions will have a relatively quick runtime with a small input, but as input grows larger, runtime can increase exponentially. This will be clear after looking at a few examples. Time Complexity Constant time, O(1) Let’s take a look at a very simple function.

No matter what the size of the input, this function will always take the same amount of time. We deduce this by the fact that there is always only going to be one “step”. Our String can be one or one thousand characters – it will still take the same amount of time to print both inputs. In this case we can say that this function runs in O(1) time, or rather, constant time. Linear time, O(n)

This function will run in O(n) time or what is known as linear time. This is due to the fact that …

What Are Higher Order Functions and Receiver Types in Kotlin?

If you have been programming Java, especially within Android, for a long time, you would know that higher order functions are not really a thing. They are, in such a way that you can pass around a functional interface, however those are not true functions (a function literal to be specific). Fear not, because Kotlin is here and allows you to do just that. A basic higher order function Kotlin allows us to define a function which takes a function (a literal) as a parameter. The syntax for this looks like the following:

We’ve written an empty function which takes a function as a parameter (simply named function  in our case) and does nothing. You should notice that we wrap our argument types in brackets, if we wanted multiple parameters, we’d use a comma to separate them. Right now, this function isn’t doing anything. Let’s change that.

From our main  method, we are now passing a lambda function to functionTest() . We can see that it takes value s  and returns s.plus("!") . All this lambda is doing, is just taking a String and returning the same String appended by a “!”. A little more complex… Higher order functions can grow to be more complex. Let’s see an example where we take a function with multiple parameters on top of having multiple statements in the return clause.

If you’re new to Kotlin, this can look a little confusing. Especially the last line of our main  method. For starters, the last line of our return clause is what is returned. We do not have to include the return  keyword for this – it can be omitted. So, we’re allowed to have an unlimited number of statements, as long as the last line is what is to be returned (a String in this case). Also, as previously stated, we separate …

Playing Sounds with SoundPool in Android

Like MediaPlayer, SoundPool can also be used to play audio files. However, unlike MediaPlayer, SoundPool is more suited for quick sound effects as opposed to longer audio files which require streaming. Before we even begin, we’ll need some sounds to work with (preferably ones with a creative commons license, or similar). You can use google for this or if you’re lazy, http://www.wavsource.com/sfx/sfx.htm.   Storing our sounds Download any number of sounds you like. In your project, create a new folder under app called assets (do not store your sound files in the res folder). You can achieve this by right clicking on app, New -> Folder -> Assets folder. Your project structure should look like the following afterwards, Once you’ve created your assets folder, create another folder within assets. You can name this folder anything you want – we’ll use it for storing our sound files.   Accessing our sound assets To take steps to make our code clean, we will be making a class dedicated to loading and playing our sounds outside of our Activities and Fragments. We’ll start with building that class now. Create a class called SoundPlayer. We’ll need a few methods which will be used to hide away the logic of accessing and loading our sound files from outside classes. Here’s my implementation of SoundPlayer. You can change/add some code to suit your needs but this is the basic gist.

The core components of this class consist of: List  for storing our Sound  objects AssetManager  for accessing our app’s asset files. SoundPool  for playing our sound files. You will also notice two different constants, SOUND_FOLDER and MAX_SOUNDS. They specify the name of the folder we’re storing our sounds and the maximum amount of sounds we allow our SoundPool to play at once, respectively. fetchSounds() is executed as soon as our class is instantiated. It first tries to locate …

Annotations in Java

Annotations in Java, we have all seen and used them in our code. Such examples are @Deprecated , @Override , @SuppressWarnings , @NonNull , @Nullable , etc. Most of us can say what these annotations imply or do, but how do they actually work? Before we discuss them in depth, let’s first understand what their purpose is. What Are Annotations? Annotations are simply metadata that we tie with our code. Meaning, extra data on top of the code we’re already writing. This metadata will be used either during compile or run time. There are three that Java includes, and they are: @Deprecated , @Override ,  @SuppressWarnings . Android also has its own large list of annotations on top of the three included in Java. You can find them here. Annotations In Practice Let’s take a quick look at one of the most common annotations every Java developer comes across: @Override . We’ll use the following Animal  class as an example.

Almost all popular IDEs of have a way of automatically providing override methods. This is done as long as the class we are extending provides no implementation for said method ( makeNoise()  is abstract ). Furthermore, the  @Override annotation is provided above makeNoise()  as well. Its purpose is to state that this class is overriding a parent method. If we were to annotate a method with @Override  that wasn’t a parent method, our IDE would show us an error similar to the one seen in the image below.  The compiler would also throw an error if we tried to build this.   How does it really work? Now you’re probably asking yourself how @Override  is able to tell both the compiler and our IDE that this is in fact an error. Let’s take a look at the code.

Surprised right? The thing with annotations is that they contain no logic. There is nothing in this …