Quick guide to build your first Android app with Kotlin

Quick guide to build your first Android app with Kotlin
Highlights

Kotlin has become quite popular since Google announced it is supporting the programming language at the Google IO 2017 conference The language is fun, expressive, and modern in nature There are many advantages of using Kotlin to develop your first Android app

Kotlin has become quite popular since Google announced it is supporting the programming language at the Google I/O 2017 conference. The language is fun, expressive, and modern in nature. There are many advantages of using Kotlin to develop your first Android app.

Kotlin helps you avoid common programming language mistakes such as NullPointerExceptions because of the built-in features that improve the quality of app development. Another advantage is the fact that Kotlin is 100% interoperable with Java and requires writing less boilerplate code which in turn saves time in testing and maintenance.

Kotlin runs on Java Virtual Machine, which is widely used for developing Android apps. Here is a simple guide to build your first app with Kotlin.

1. Android Studio

To build apps using Kotlin, you will need to have Android Studio installed on your machine. The platform works seamlessly with Windows, Mac and Linux. The installation process is similar across all platforms.

2. Create Project

Once you have setup Android Studio, you need to click on create project. On the welcome screen, click on Start a new Android Studio project. In the new project dialog box, enter the name of your first project. Accept the default example domain. Check the box that reads ‘include Kotlin support’.

Accept the default project location and go to the next step. In Target Android Dialog, accept the defaults, and click Next. Select empty activity here and click next. In the customize activity dialog box, you will find an option to accept default.

3. Create user interface

Let’s look at an example of building a counter app with plus button to increment the value and minus to decrement the value. You can easily create the user interface by using existing components. The user interface of an app made with Kotlin will give the following three components:

•A Plus Button to increment the Counter

•A Minus Button to decrement the Counter

•A TextView to display the value of the Counter

4. Write code of the main activity

The Kotlin Android Extension Plugin does this job easily. You need not make findViewById() calls while writing the first app. You can give references of Views in MainActivity easily with the extensions plugin. Under the main activity, you need to define a property to store value of the counter. Once you set OnClickListener on the plus and minus buttons to update Counter value, Android Studio will generate the code.

5. Testing the app made with Kotlin

You can click on build button to test the app. Android Studio will run the app in emulator that will help you test the app.

Source: techgig.com

Show Full Article
More Stories
Top