Categories
Coding Project Tutorial

KitKat – Android/Nodejs/Git Tutorial part 2 Understanding Android

Welcome back,
So last we left off, we installed Git, Android studio, Github, Nodejs, Sublime text 3.

Now we’re ready to do some actual coding…Sorry not yet. Before we get there we need to understand a little bit of things.

In this section, we’ll try understanding Git and Android applications.

If you don’t like theory, you can skip over this section. But But But I highly recommend reading through especially, if you have a large project to work on.

First of What is Git and why do we use it?

Git is a distributed version control system.

Big words but what do we actually use it for…

Basically Git has these 3 purposes:

  1. Git is used to keep track of any changes you make to your application/code. Every time you make any changes, you’ll have to let git know of them. Then later, if you ever destroy an important file or completely break the code, you’ll be able to travel back to any version of the code where you made any change.
  2. Git is used for collaboration. Working with others can be really hard, especially if you are both editing the same file. Git allows each member to have their own copy of the code. It also has a smart merging feature which makes integrating code much easier.
  3. Git is used to store your code. Git’s slick way of storing files allows us to easily access files anywhere as long as we have access to a computer with git. This is especially helpful when we get to deployment.

If this goes over your head don’t worry, we’ll be doing these step by step. Right now you just need to know the first point, Git is used for keeping track of changes to your code.

How it does it? Not that important but it creates these hidden folders that log every information about your project.

Android

Last thing before we get started. We need to a little bit about android applications. Android is the operating system for most mobile devices. That means we have a lot of devices of different screen sizes, battery sizes, and other capabilities. Some don’t have fingerprint scanners and some don’t even have cameras. Thus Android applications need to be compatible with many attributes.

The Android operating system architecture looks like this

  • Applications that run on the phone
  • Application Framework that are like APIs we use to communicate with different device services
  • Libraries provided features like encryption and database management to Android applications
  • Kernel which provides the drivers to communicate with device specifics
  • Android runtime which has the core libraries and the virtual machine that compiles all android code to device specific code. if you have done Java before, the DVM is very similar to the Java Virtual Machine. Actually the real reason DVM is used at all is because of java and how java can run on any device as long as there is a JVM. The DVM was replaced by Android runtime which uses ahead of time compilation. Thus better performance
Android-System-Architecture - Android (operating system ...

Note: The important thing to note here is just the general structure and that all code gets compiled using a VM, this may make android applications slower to run than iOS application but android runtime performs this ahead of time so it’s not really slower.

Android uses runs each application in a sand-boxed environment, this means that no application can communicate with each other unless they do some extra set up. This makes android applications secure and robust as a single application crashing will not affect the others.

Back to android applications, the main thing you need to know is that a lot of android applications follow the Model View Controller design pattern.

Why do we need to know about this?

Design is really important when building application. Having a good understanding and building good design can save you so so so much time.

Design patterns are ways of structuring the client of applications. There are many design patterns to building applications. I’m still learning about them. I know some companies care a lot about design patterns, so you could look into them if you want.

More importantly MVC is a design pattern that prioritizes separation of concern. There are just 3 parts to it:

  • View
    • This is what the user sees and interacts with. When you use any application, the portion of the application that you interact with is the View.
  • Model
    • Model is the part of the application that structures and holds the data. If you’re familiar with object oriented programming, think of models as simple classes that just have getters and setters.
  • Controller
    • So we have what the View that the user interacts with and the model where the application and user data are stored. BUT the Model and View don’t talk to each other so how does the applications work. This is where the Controller comes in. When the user interacts with the View, this will trigger Events in the controller and this in turn may lead to changes in the model. If the model is changed, it informs the controller of the changes and the controller updates the views.
6s183 - Lecture 3

Android kinda mixes these concepts together when we build the app we’ll see how it works. For now, think of these android parallels:

  • View = layout files in Android studio
  • Model = Java classes that structure data
  • Controller = Activities that connect classes to layouts

If you don’t quite get it, don’t worry, it’s just a concept involving separating concerns. Often, we end up mixing them. It’ll be clearer when we go over them

Android life-cycle

Last thing we need to look at the life cycle of the Activity

Basically, an android application can be divided into Activities(different pages). Each Activity(page) has a life-cycle, that means it runs certain events when things happen to the activity. In summary, it looks like this:

Android Activity Lifecycle - Androhub

This will be clearer when we build our first application.

Think of these as functions that get called when different events occur to the application.

I think this is way too much information for a post so I’m just gonna stop here and move the actual coding to next time.

Really Sorry I know this one was really boring but I just wanted to go over the most imp theory before starting the fun stuff😭

If you made it this far, you are now ready to kick some android butt and an incredible designer.

To Summarize:

Git is used to track changes, collaboration, and storing code. Android has VM that allows it to run on any device. Android apps are sand-boxed thus secure. MVC is a design pattern that focuses on the separation of concern. We can think of java classes as models, layouts as views, and activities as controllers. Activities have their own life-cycle

Next time, we’ll be building a simple Android app and putting on Github.

Thank you so much for reading😭. Feel free to contact me if you have any questions. Even if it’s how you are doing or what you’re building.

By humaidk2

Humaid is a full stack developer who has a passion for building applications with artificial intelligence. You can get more info at humaidkhan.com

Leave a Reply

Your email address will not be published. Required fields are marked *