Show List

Creating The First Android app

Here is how to create your first Android app with some code examples.

  • Open Android Studio and create a new project. Choose the "Empty Activity" template and give your app a name and package name.
  • In the "MainActivity.java" file, add the following code to display a simple "Hello, World!" message when the app is launched:
java
Copy code
package com.example.myfirstapp; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView textView = findViewById(R.id.textView); textView.setText("Hello, World!"); } }
  • In the "activity_main.xml" layout file, add a TextView element to display the message. The code should look like this:
xml
Copy code
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, World!" android:textSize="24sp" android:layout_centerInParent="true" /> </RelativeLayout>
  • Run the app on an emulator or physical device. To do this, click on the "Run" button in the toolbar, select your device or emulator, and click "OK". After the app is installed and launched, you should see the "Hello, World!" message displayed on the screen.

Congratulations! You have created your first Android app. Of course, this is a very simple example, but it demonstrates the basic components and structure of an Android app. From here, you can start exploring more advanced features and functionality, such as user input, data persistence, networking, and more.


    Leave a Comment


  • captcha text