In the earlier tutorial we created an Android App Project using the Android Studio. In this video tutorial we look at the key files which are part of the Android Project.
We look at the Activity file, the layout file and also talk about the role of Gradle which helps build and deploy the App.
Activities We use Activity to define what the App does. Like when we click on a button what needs to happen can be defined using an Activity. It’s a class written in Kotlin.
Layouts To define how a screen in your App will look like we use an XML file. A screen can have various elements like images, text etc.
We use Layouts to define the UI and Activities to define the behaviour. Similar to what we do with websites – HTML, CSS and Javascript.
Like if you need to add a button then we use Layout to specify its position on screen and Activity to add functionality.
We bundle all these files together and that’s what an App is.
What happens when you start an App ?
Sequence of events when you start an Android App
When you start an Android App the main activity is called.
This tells Android to use a particular Layout.
The layout is displayed on the device.
The user interacts with the layout.
The activity responds to these interactions, and updates the display.
Why Kotlin ? It’s preferred because of additional features and it’s concise nature.
Why Android Studio ? It includes a set of code editors, UI tools and templates, which are all designed to make development easier and faster. It also comes with Android SDK which is needed to develop Apps. It includes Android source code and also a compiler to compile the code you write to Android format.
Select a project template – Choose the Empty Activity option.
Configure the project – Specify the app name, package name and save location. Be careful with the version you select. We will discuss more on this in future blog, but you need to consider which versions of Android you want the app to be compatible with. If you specify that the app is only compatible with the very latest version of the SDK, you might find that it can’t be run on many devices.
That is it, your first app is ready. Congratulations !!
When your App is built to run on Android devices only. The advantages of building a Native app includes high performance, access to native APIs and features and better user experience. The disadvantages may include longer development time, higher development costs and platform-specific development.
What Tools and Technologies can be used to build a Native Android App ?
For native Android development, you can use the following tools and technologies
Java or Kotlin programming languages – Both Java and Kotlin are popular programming languages for Android development. While Java has been the traditional language for Android development, Kotlin is gaining popularity due to its concise syntax and modern features.
Android Studio – Android Studio is the official Integrated Development Environment (IDE) for Android app development. It comes with a set of tools and features that simplify the development process and speed up app development.
Android SDK – The Android SDK is a collection of software development tools and libraries required for building Android apps. It includes tools for developing, debugging, and testing Android apps.
Android Jetpack – Android Jetpack is a set of libraries and tools that help developers build high-quality apps faster. It includes components for handling UI, background processing, navigation, and more.
Firebase – Firebase is a mobile and web application development platform that provides a range of features and services to simplify the app development process, such as real-time databases, push notifications, authentication, and analytics.
Third-party libraries – There are various third-party libraries and tools available for Android development that can help you add functionality to your app or speed up development. Some popular ones include Retrofit for network communication, Glide for image loading and caching, and Dagger for dependency injection.
These are some of the most commonly used tools and technologies for native Android development. You can use them to create high-quality and feature-rich Android apps.
Steps to create a Native Android App
Let’s look at the steps to create a simple Native Android App
Set up your development environment: To develop native Android apps, you’ll need to download and install Android Studio, which is the official IDE for Android development. Android Studio comes with the Android SDK and all the necessary tools you need to build and test your app.
Create a new Android project: After setting up your development environment, create a new Android project in Android Studio. This will generate a default app structure with a basic user interface.
Design the user interface: Android Studio comes with a visual layout editor that allows you to drag and drop UI elements onto the screen and customize their properties. Use this editor to create the user interface for your app, and add functionality to the UI elements by writing code in Java or Kotlin.
Write your app logic: Once you’ve designed the user interface, write the code that handles user interactions and performs the necessary tasks to make your app work. This might include retrieving data from a database or web service, processing user input, or manipulating media files.
Test your app: After you’ve finished writing your app, test it on a physical Android device or an emulator to ensure that it works as expected. Android Studio comes with a built-in emulator that allows you to test your app on various Android versions and device configurations.
Publish your app: Once you’ve tested your app and made any necessary changes, you can publish it on the Google Play Store, which is the official app store for Android. To publish your app, you’ll need to create a developer account, submit your app for review, and follow Google’s guidelines for app publishing.
Android framework makes it quite easy for you to generate different flavors and variants of your App. Like you can create a free version or a paid version of your App.
In order to do this you need to follow these steps:
You need to specify the variants or flavors in your App’s build.gradle file.
In all likelihood your Free App version will need a different Activity compared to the Paid one. So you need to create different folders for the two flavors.
So go to the Project->src folder and create a new Java Folder – free.
Create another one for paid similarly.
Add appropriate Activity and other files to this folder.
And you are all set. Execute Generate Signed APK task from the Build option. This will ask you which flavor you need the APK for.
You saw why using modules is important and how to create a Java module in an earlier Post. In a similar fashion you can add an Android module to your project.
Android Studio makes it easy to add a new module. Follow the video to understand the steps.
An ADB is a command line tool which can be used to communicate with Emulator or Android Devices.
When your development machine needs to communicate with an Android Device it does so using ADB. It’s a process that is controlled by a command also known as adb.
The adb command works by talking to an adb server which runs in the background at port 5037. The server is also known as adb daemon or adbd.
Android Studio also talks to this server when it needs to run an app via an Android Device.
Once you have transferred an APK file to your Android device its stored in /data/app/<package-name>
The classes.dex file is extracted from it and it’s converted to native library, when the App is run the first time, and stored in /data/dalvik-cache. This Machine Code can be run by the CPU.
Each Android device runs a process called Zygote. When an App needs to run Zygote creates a forked version of itself. Which means its a process in memory. Using this forked process and by loading the native library the App can be loaded pretty quickly.