android hello world example

https://w‮ww‬.theitroad.com

Here is a step-by-step guide to creating a "Hello, World!" Android app using Android Studio:

  1. Open Android Studio and create a new project by selecting "Start a new Android Studio project" from the welcome screen.

  2. Enter the application name and package name. You can choose a minimum SDK version and a target SDK version, as well as select the language for your app (Java or Kotlin).

  3. Choose a project template. For our "Hello, World!" app, we can select "Empty Activity" template.

  4. Android Studio will then generate the project files and open the main activity file (MainActivity.java or MainActivity.kt).

  5. In the main activity file, locate the onCreate() method and add the following code to display the "Hello, World!" message on the screen:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TextView textView = findViewById(R.id.textView);
    textView.setText("Hello, World!");
}

If you are using Kotlin, the code will look like this:

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    val textView = findViewById<TextView>(R.id.textView)
    textView.text = "Hello, World!"
}
  1. Save the changes and run the app by clicking on the "Run" button or by selecting "Run" from the menu.

  2. Android Studio will prompt you to select a device or an emulator to run the app on. Choose a device or create a new virtual device and click "OK".

  3. The app will be installed on the selected device or emulator, and you should see the "Hello, World!" message displayed on the screen.

Congratulations! You have just created your first Android app using Android Studio. From here, you can continue to experiment and build more complex apps using the Android SDK and the powerful tools provided by Android Studio.