Android Development Tutorial

AuthorSumit Dey Sarkar

Pubish Date26 Jan 2023

categoryAndroid

In this tutorial we will learn android development from basic to advace.

Let's start learning android development

 

Introduction to Android Development

Android is one of the most popular operating systems with over 88% of phones running android.

 

XML & Java Code

An XML  file is used to build layout in Android. Layout are static pages (Screen) which can  be manipulated using Java code (programmatically).

 

Installing Android Studio

Android studio is an IDE that makes it easy for us to write & build UI layouts using drag and drop features.

You can go to https://developer.android.com/studio to download android studio.

 

The Layout Editor

In Android Studio we can quickly build layout by dragging UI element using layout editor and in this also we write XML by hand very easily.

Using layout editor we can setup different attributes easily using the design mode in android studio.

 

Android Development Layout

 

 

Chapter 1

Creating our first App

In this chapter we will create our first android app.I don't expect from you to know anything but will walk you through the steps to build your first Android App!

 

What is an APK?

An APK is a collection of different files (like code, audio, video, etc) compiled and bundles into a single file.

 

What is an AVD ?

AVD stands for Android Virtual Device.

Android virtual device (AVD ) is an emulator configuration which simulates a physical Android Device in android studio.

 

Android UI Layouts

View are the base class for widgets (Like butons, text fields etc.)

( Here View is a  Basic building block)

View Group hold view and view Group

(Here View Group is a box (container) which can hold objects and more boxes)

Android Development View Group

 

XML vs Java in Android

XML is the skeleton code which describe the UI layout and Java drives this XML

XML vs Java In Android

When submit is clicked { Change the screen + store the data} using Java.

 

Important Points About Android Studio

  • Android Studio is a resource hungry program. So, need to have patience while using android studio.
  • Sometimes Android studio might download files from the internet, so keep your wifi / hotspot ready.
  • Not many time but sometime your firewall may be blocked Android Studio. In this case you will need to unblock android studio from firewall.
  • If your computer working slow then use USB debugging to use your phone as an AVD replacement.
  • If you are using an low configuration PC, then you need to Make sure that the virtualization is turned on.

 

Creating our Unit Converter App

Step 1 - Click on New Project

Android Studio

 

Step 2 - Click on Empty Activity

Android Studio

 

Step 3 - Click Next

Android Studio

 

Step 4 - Type the name of your App and click finish

Android Studio

 

Step 5 - Wait for the gradle build finish

Android Studio

 

The R.java file

Android R.java file contails resource IDs for all the resource. We can use it to access views from our java file.

Button = find view by Id (R.id.mybotton);

Here find view is a function to access view and mybutton is a id of button in XML.

 

Adding Event Listeners

We can add on click listeners by using set on click listener method as follows.

button.SetonClickListener(new view.OnClickListener())
    @ override
    public void on click (view v) {
// Write action here,what you want 
}
});

 

android: onClick attribute

In button XML layout element, the onClick attribute can be set.

In XML

android : onClick = "SendMyMessage" 

 

In Java

public void SendMyMessage(view view){
// Code here
}

 

 

Chapter 2

Java Refresher

Java is an amaging object oriented programming language. We will use java to create android apps.

The main method

The java program starts executing from here

public static void main (string [ ] args) {
//code
}

 

Printing to the console

The  following code prints "Hello World" to the console :

System.out.println("Hello, World");

Variable in java

Variables are buckets in memory

String actionNow; -  String is used to store seq of characters

int marks; - int is used to store numbers

int value = 7; 

Variabe in java

 

Comments

// Comments are used to write text which doesn't executes

// This is a comment

/* This is a multiline comment */

 

Strings in java

String = Sequence of charecter

String name = "Harry" (Strings are immutable and not changable)

 

Printing strings

We can concatenate string like this:

System.out.println("Hello" + "World");

 

String methods

String name = "Harry"

name.length()

name.toLowerCase

name.trim()

 

Other data types to store numbers

We can store numbers using

byte : -128 to 127

short :  -(216 / 2) to (216 / 2 -1)

int :  -(232 / 2) to (232 / 2 -1)

float : Used to store decimal values (4 bytes) [ ex. 10.if ]

long : -(264 / 2) to (264 / 2 -1)

double : Decimal values of 8 bytes [ex 7.88d]

Comments 0

Leave a comment