Learn Android Basics!

When you want to start to learn how to developing android application, my recommendations you should start by learn android app component and views. This two things is very important when you building an android application.

Android App Components

Each of android app components is an entry points to use and android application whether is triggered by user or by android system, there are 4 types of android app components:

  1. Activities

    An activity is the entry point for interacting with the user. It represents a single screen with a user interface.

  2. Services

    A service is a general-purpose entry point for keeping an app running in the background for all kinds of reasons. It is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface.

  3. Broadcast Receivers

    A broadcast receiver is a component that lets the system deliver events to the app outside of a regular user flow so the app can respond to system-wide broadcast announcements. Because broadcast receivers are another well-defined entry into the app, the system can deliver broadcasts even to apps that aren't currently running.

  4. Content Providers

    A content provider manages a shared set of app data that you can store in the file system, in a SQLite database, on the web, or on any other persistent storage location that your app can access.

Views and View Groups

View class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. View is the base class for widgets, which are used to create interactive UI components (buttons, text fields, etc.). The ViewGroup subclass is the base class for layouts, which are invisible containers that hold other Views (or other ViewGroups) and define their layout properties. There is several view group that you can use:

  1. Linear Layout

    A layout that arranges other views either horizontally in a single column or vertically in a single row.

  2. Frame Layout

    Frame layout is a ViewGroup subclass that is used to specify the position of multiple views placed on top of each other to represent a single view screen.

  3. Relative Layout

    Relative Layout 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 Relative Layout area (such as aligned to the bottom, left or center).

To build views in android application you can use xml as language to construct yout view like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Hello World!" />

</LinearLayout>

Or you can set view directly using view classes, like this:

...

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    val layout = LinearLayout(this).apply {
        val textView = TextView(this@MainActivity).apply {
            text = "Hello World!"
        }
        addView(textView)
    }
    setContentView(layout)
}

...

sources:

https://developer.android.com/guide/components/fundamentals

https://developer.android.com/reference/android/view/View