Learning From Home with BNCC Academy in Collaboration With Go Academy

William Chang
9 min readSep 17, 2020

--

Hello, recently we are from Bina Nusantara Computer Club (BNCC) have a very great opportunity to learn from Gojek, one of the biggest tech company and personally its my most favorite company when it comes to sharing knowledge.

Started by me and 31 other friends from BNCC are participating on BNCC Academy as a learning collaboration with Go Academy and we are learning one of the most popular language in 2020, Kotlin. This academy held on 1 month duration and the final goal is to make an COVID-19 tracker application built in android platform. Unfortunately, during the pandemic nowadays we are forced to held this program from our home, but its okay because we must keep learning anytime and anywhere.

This academy is divided into 5 learning session

  • Intro with Kotlin, Android Studio, View and Layout
  • Activity Life cycle, Intent and Intent Filter
  • Display list of data
  • Remote data source
  • App Architecture

So from here i’m gonna wrap up all things that i have been learned during this academy.

Intro with Kotlin, Android Studio, View and Layout

This is first day in this academy. We’ve been learning about Kotlin in general. The coaches in academy in this academy explains about basic syntax on Kotlin and since i’m from Java developer itself, i found that there are several differences between Kotlin and Java.

Lets see on example between Kotlin and Java in printing “Hello World”

It’s pretty short right? but look at this comparison

See the difference? Kotlin make the code is shorter and easier to read right? for android development specifically, Jetbrains as the creator of Kotlin language make a comparison of android development trends where almost everyone develop android apps using Kotlin. But beside of that, Kotlin is more type safety where it reduce a chance of NullPointerException where most of Java developer hates it. You can read more about Kotlin in here https://kotlinlang.org/

About Android Studio its a simple IDE for developing android application and we are using Gradle as package manager and build the apps. There are also many kinds of view layout in android.

  • Frame Layout

FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that’s scalable to
different screen sizes without the children overlapping each other. Child views are drawn in a stack, with the most recently added child on top.

  • Linear Layout

LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute.

  • Relative Layout

RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).

  • Constraint Layout

ConstraintLayout allows you to create large and complex layouts with a flat view hierarchy (no nested view groups). It’s similar to RelativeLayout in that all views are laid out according to relationships between sibling views and the parent layout, but it’s more flexible than RelativeLayout and easier to use with Android Studio’s Layout

Activity Life cycle, Intent and Intent Filter

In day 2, we learned about activity and how to connect the with intent. Activity is a part of application that serves as the entry point for app interaction with user. Activity must be registered in manifest for example

<manifest ... >
<application ... >
<activity android:name=".ExampleActivity" />
...
</application ... >
...
</manifest >

Also you can add another permission such as location, phone calls, contacts, etc and register them in manifest also.

On android activity, there are several life state to determine their states like stopped, resuming an activity, destroying process, etc. All of those states are described in image below

  • onCreate

Triggered when an activity is opened, its recommended to only do basic operation in this activity like setting event listener on component or getting data.

  • onStart

Triggered when an activity is ready to be displayed in user screen. It will trigger onResume after the callback is finished and the activity state will be onResume

  • onResume

Triggered after onStart callback is finished. The apps will stay on this state until user is take focus away from the app such as receiving phone call, opening another activity or turning off device screen.

  • onPause

Triggered after user leaving apps and it will be first indication that user leaving apps. When the apps in this state, the apps actually freeze and running on this state. So, onPause is keep running until user open the apps again and it will trigger onResume

  • onStop

Triggered after the activity is not visible into user, its a first indication that the activity will be turned off.

  • onDestroy

Triggered after activity is destroyed. It need to be done because in some case the system needs to be shut down gracefully to prevent an unexpected problem.

To communicate between activities we are using intent. Intent can be user to transfer data from activity to another activity and there are 2 type of intent:

How intent works
  • Explicit intent

Explicit intents specify which application will satisfy the intent, by supplying either the target app’s package name or a fully-qualified component class name. For example: intent to pass data from activity A to activity B.

  • Implicit intent

Implicit intents do not name a specific component, but instead declare a general action to perform, which allows a component from another app to handle it. For example, if you want to show the user a location on a map or calling. We can use custom intent that provided by the system itself

Display list of data

In day 3, we are learning about how we make a reusable component with recyclerView. RecyclerView helps developer to display a list of data in the
flexible manner
. Instead of rendering all the data, RecyclerView will
intelligently render only the data that is visible on the screen. RecyclerView cannot work alone, it needs a cooperation with LayoutManager, Adapter, and ViewHolder.

  • Adapter is responsible for binding data into view, in adapter, the data is on List and will be divided later
  • ViewHolder is responsible for mapping data from adapter into view, in viewHolder data is already divided into single object
  • LayoutManager is responsible for mapping what intent should be used to communicate

Remote data source

In day 4, we learned about how we get data from outside source. In this session we learned about how to get data via HTTP with JSON format. Lets say we have 5 heavy task that run on single thread where every task is running on 6 second each, so the total it will need 30 second to get things done.

As a developer we don’t want things like that happened right? Well there are multi threading comes to rescue. Instead of they are running synchronously why don’t we make them run asynchronously so the task can be done only for 5 seconds well that’s a big difference from previous example right?

In android we can utilize multi threading with asyncTask (But is way too deprecated), ThreadPool Schedulers, Kotlin Coroutines.

Now back into taking that data from HTTP into our apps. There are also many ways to do a HTTP request, some of them are:

  • HttpURLConnection and HttpsURLConnection (But its deprecated)
    The OG way to do networking in Android (dating back to Android 1.0) and actually are java.net APIs
  • OkHttp
    Really popular and really well-made 3rd-party networking library for Android, maintained by Square
  • Retrofit
    Retrofit extends OkHttp API to provide a practically child-proof REST client library and also maintained by Square

Note: When added request HTTP into your project, make sure to add internet and access network state in manifest.xml

For the okHttp implementation example in here

As you can see here, the object callback that we implemented after the request is done and it will takes onSuccess or onFailure in case the server is not responding.

Notes: if you want to update UI on the callback function, you might use runOnUiThread because it runs on different thread

Its also an implementation of kotlin coroutines with okHttp where stuff runs asynchronuously on main thread and after the request is done, it will be handled by callback object.

App Architecture

It’s final session and i think its the most interesting session. The coaches explains about how there are engineering problem, such as under engineering and over engineering.

Under engineering is condition where you code as long as the feature is fulfilled where you need a short time left for releasing and don’t care about the development further.

For example when you are building an house and have a weak foundation, it will be broken as time goes by because it’s not built properly.

On the other hand, on over engineering hands when you are thinking too much about how to make a code clean and looks good but in the end you are just made the code is less readable and hard to refactor

An Illustration on how over engineering code hard to read

But there are a ways to resolve that. We can use a design pattern and specifically, it will use an architectural pattern. In android development itself, there are 3 popular architectural pattern.

  • MVC stands for Model, View, Controller
  • MVP stands for Model, View, Presenter
  • MVVM stands for Model, View, ViewModel

MVC was a popular architectural pattern for android development then. But nowadays, people will use MVP or MVVM architectural pattern for android development. Because MVC in android cause it cause thigh coupling. MVP and MVVM is less coupling and high cohesion.

As the image below, MVC is running on one way buat MVP and MVVM have 2 ways to communicate. In MVP and MVVM the view is not just subscribing for some event and the Presenter and ViewModel will inform them about what things need to be done and passing some data or command to view not like MVC where View need to know about what kind of action that will be done when Controller is calling for specific View. Also another advantage on this pattern it’s easier to test, just call interface from each component annd you can mock it easily.

The difference between MVP and MVVM is MVVM using Observer pattern , the view is subscribing for some event and the ViewModel broadcast all the message to view.

With this architecture, we can split the application into some specific functionality, Model is responsible for doing query to database or calling an API in order to get or send some data. Controller, Presenter and ViewModel responsible for handle business logic from Model and send into View. View responsible for rendering UI for user screen.

So, that wraps up about what i’ve been learned in BNCC Academy. Also special thanks for Go Academy and BNCC team for holding this amazing learning event where we can learn even though in this pandemic situation. About our final project can be found in https://github.com/WilliamChang80/bncc-gojek

Thank you for reading this post, i hope this blog can help you to get better at android development and see you soon :)

--

--