BASIC KNOWLEDGE:
Android apps are built as a combination of components that can be invoked individually. For example, an activity is a type of app component that provides a user interface.
The “main” activity is what starts when the user taps your app icon, but you can take the user straight into a different activity from other places, such as from a notification or even from a different app.
Other components such as broadcast receivers and services also allow your app to perform background tasks without a user interface.
After you build your first app, learn more about the other components at App Fundamentals.
Android allows you to provide different resources for different devices. For example, you can create different layouts for different screen sizes. Then the system determines which layout to use based on the current device’s screen size.
If any of your app’s features need specific hardware, such as a camera, you can query whether the device has that hardware at runtime and then disable the corresponding features if not. You can also set some features as required so Google Play won’t allow installation on devices without them.
After you build your first app, learn more about device configurations at Device Compatibility.
Create an Android project:
First, be sure you have installed the latest version of Android Studio. Download Android Studio here.
- In the Welcome to Android Studio window, click Start a new Android Studio project.
- Or if you have a project opened, select File > New Project.
-
- In the Create New Project window, enter the following values:
- Application Name: “My First App”
- Company Domain: “example.com”
You might want to change the project location. Also, if you want to write a Kotlin app, check the Include Kotlin support checkbox. Leave the other options as they are.
- Click Next.
- In the Target Android Devices screen, keep the default values and click Next.
- In the Add an Activity to Mobile screen, select Empty Activity and click Next.
- In the Configure Activity screen, keep the default values and click Finish.
After some processing, Android Studio opens the IDE.
First, be sure the Project window is open (select View > Tool Windows > Project) and the Android view is selected from the drop-down list at the top of that window. You can then see the following files:
- app > java > com.example.myfirstapp > MainActivity
- This is the main activity (the entry point for your app). When you build and run the app, the system launches an instance of this
Activity
and loads its layout. - app > res > layout > activity_main.xml
- This XML file defines the layout for the activity’s UI. It contains a
TextView
element with the text “Hello world!”. - app > manifests > AndroidManifest.xml
- The manifest file describes the fundamental characteristics of the app and defines each of its components.
- Gradle Scripts > build.gradle
- You’ll see two files with this name: one for the project and one for the “app” module. Each module has its own
build.gradle
file, but this project currently has just one module. You’ll mostly work with the module’sbuild.gradle
file to configure how the Gradle tools compile and build your app. For more information about this file, see Configure Your Build.
Lastly run the app by connecting your phone with the developers option enabled or run it on an emulator.
- In the Create New Project window, enter the following values:
Do you have any news or article you would like us to publish? Kindly reach us via outreach@t4d.co.ke or howtodoafrica@gmail.com.