KEMBAR78
Kotlin for Android App Development Presentation | PPTX
Kotlin for Android
App Development
Nadra Ibrahim, Rishika Kumari
Lack of etiquette and manners is a huge turn off.
KnolX Etiquettes
▪ Punctuality
Join the session 5 minutes prior to the session start time. We start on
time and conclude on time!
▪ Feedback
Make sure to submit a constructive feedback for all sessions as it is
very helpful for the presenter.
▪ Silent Mode
Keep your mobile devices in silent mode, feel free to move out of
session in case you need to attend an urgent call.
▪ Avoid Disturbance
Avoid unwanted chit chat during the session.
Agenda
1. Why Kotlin?
2. Learning by doing
• Softwares required
• Develop a basic android app
• Run on Emulator
3. Folder structure
❖ Manifest Folder
• App Components
• Intent
• Intent Filters
❖ Java Folder
• Activity
• Activity Lifecycle
❖ Res Folder
• Layout
• Declare UI elements in XML
• Load the XML resource
❖ Gradle scripts folder
1. Demo
Why Kotlin?
Kotlin
Kotlin is a high level programming language developed by JetBrains in 2010. It was developed
primarily to address the shortcomings of the Java programming language and to provide a
modern, efficient, and safe alternative to it.
Features:
● Open source,
● Easy to learn,
● Cross-platform,
● Statically-typed, concise and expressive,
● Interoperability with Java,
● Seamlessly Integrated with Android Studio,
● Null safety,
● No More NullPointerExceptions,
● has both object-oriented and functional constructs,
● Google’s Android Team has announced it as an official language for Android Application
Development.
Learning by doing
Android Studio
Android Studio is the official integrated development environment for Google's Android operating
system, built on JetBrains' IntelliJ IDEA software and designed specifically for Android
development.
Emulator
The Android Emulator simulates Android devices on your computer so that you can test your
application on a variety of devices and Android API levels without needing to have each
physical device.
Physical device
Connect your Android device to your computer via their USB ports and run the app in Android
Studio on a physical Android device.
Develop a basic android app
• Install and open Android
Studio.
• New Project > Empty Views
Activity.
• Enter name of your project and
package.
• Select the location to save
your project.
• Select Kotlin as the language
• Leave the minimum sdk as it
is.
• This will develop a default
android app for you.
Run on Emulator
The emulator comes with Android Studio, so you don't
need to install it separately. Follow these basic steps :
● Verify that you have the required system
requirements
● Go to device manager and select create device.
● Select your phone, then next.
● Choose system design, download it and finish. This
will create a virtual device, that will run on Android
studio.
● In the toolbar, select the AVD that you want to run
your app on from the target device menu. And click
run.
Folder structure
Folder structure
Contains an XML file which contains important
metadata about the Android app.
Contains source code and test files.
Contains resources (for design).
Contains the build configuration files for the
project.
Manifest Folder
Manifest Folder
Every app project must have an AndroidManifest.xml file, with precisely that name, at the root of
the project source set., inside the manifest directory. This file is created for you and most of the
essential manifest elements are added as you build your app.
This file contains information about our application such as the Android version, metadata,
states package for Kotlin file, and other application components. It acts as an intermediary
between android OS and our application.
Among many other things, the manifest file is required to declare the following:
● The components of the app,
● The permissions that the app needs in order to access protected parts of the system or
other apps. It also declares any permissions that other apps must have if they want to
access content from this app.
● The hardware and software features the app requires, which affects which devices can
install the app from Google Play.
App Components
For each app component that you create in your app, declare a corresponding XML element in
the manifest file.If you subclass any of these components without declaring it in the manifest file,
the system can't start it.
Specify the name of your subclass with the name attribute, using the full package designation.
For example, To declare your activity, open your manifest file and add an <activity> element as
a child of the <application> element.
Intent
App activities, services, and broadcast receivers are activated by intents. An intent is a message
defined by an intent object that describes an action to perform, including the data to be acted on,
the category of component that is expected to perform the action, and other instructions.
Although intents facilitate communication between components in several ways, there are three
fundamental use cases:
● Starting an activity
● Starting a service
● Delivering a broadcast
There are two types of intents:
● Explicit intents specify which application will satisfy the intent, by supplying either the
target app's package name or a fully-qualified component class name.
● Implicit intents do not name a specific component, but instead declare a general action to
perform, which allows a component from another app to handle it.
Intent Filters
When an app issues an intent to the system, the system locates an app component that can
handle the intent based on intent filter declarations in each app's manifest file. The system
launches an instance of the matching component and passes the Intent object to that
component. If more than one app can handle the intent, then the user can select which app to
use. An app component can have any number of intent filters (defined with the <intent-filter>
element), each one describing a different capability of that component.
You can take advantage of this feature by declaring an <intent-filter> attribute in the <activity>
element. The definition of this element includes an <action> element and, optionally, a
<category> element and/or a <data> element.
This intent filter tells that this is a launcher activity, that is, it will be the first to open up.
Java Folder
Java Folder
The Java folder contains all the java and Kotlin source code (.java) files that we create during
the app development, including other Test files.
There are multiple packages inside this directory :
com.package.projectname : When we create any new project using Kotlin, by default the class
file MainActivity.kt file is created automatically under the package name.
test directory : This directory is for pure unit test that do not involve android framework. You can
run tests here without running on a real device or on emulator.
Android test directory : This directory is for unit tests that involves android instrumentation.
Activity
An Android app typically consists of multiple activities that work together to provide a seamless
user experience. Unlike traditional programming paradigms with a main() method, Android apps
are built around the concept of components, and the Activity is a fundamental component.
When one app invokes another, the calling app invokes an activity in the other app, rather than
the app as an atomic whole. In this way, the activity serves as the entry point for an app's
interaction with the user. An activity implemented as a subclass of the Activity class.
An activity provides the window in which the app draws its UI. Generally, one activity implements
one screen in an app.
To use activities in your app, you must register information about them in the app’s manifest,
and you must manage activity lifecycles appropriately.
Activity Lifecycle
The activity has some predefined functions to handle the state changes in the application’s
activity. Override the functions to achieve the required functionality when the activity’s state is
being changed.
Res Folder
Res Folder
Contains all non-code resources, such as UI strings and bitmap images, divided into
corresponding subdirectories.
res/drawable folder : contains the different types of images used for the development of the
application. We need to add all the images in a drawable folder for the application development.
res/layout folder : contains all XML layout files which we used to define the user interface of
our application. It contains the activity_main.xml file.
res/mipmap folder : contains launcher.xml files to define icons that are used to show on the
home screen. It contains different density types of icons depending upon the size of the device
such as hdpi, mdpi, xhdpi.
res/values folder : contains a number of XML files like strings, dimensions, colors, and style
definitions. One of the most important files is the strings.xml file which contains the resources.
res/xml folder : contains arbitrary XML files that can be read at runtime.
Layout
A layout defines the structure for a user interface in your app, such as in an activity. All elements
in the layout are built using a hierarchy of View and ViewGroup objects.
A View is defined as the user interface which is used to create interactive UI components such
as TextView, ImageView, EditText, RadioButton, etc., and is responsible for event handling and
drawing. They are Generally Called Widgets.
A ViewGroup act as a base class for layouts and layouts parameters that hold other Views or
ViewGroups and to define the layout properties. They are Generally Called layouts.
Declare UI elements in XML
We can create a layout similar to web pages. The XML layout file contains at least one root
element in which additional layout elements or widgets can be added to build a View hierarchy.
Load the XML resource
When you compile your app, each XML layout file is compiled into a View resource. Load the
layout resource in your app's Activity.onCreate() callback implementation. Do so by calling
setContentView(), passing it the reference to your layout resource in the form:
R.layout.layout_file_name. Generally, during the launch of our activity, the onCreate() callback
method will be called by the android framework to get the required layout for an activity. Also we
can access the UI element from the XML using findViewById.
Gradle scripts Folder
Gradle scripts folder
Gradle means automated build system and it
contains a number of files that are used to define a
build configuration that can be applied to all modules
in our application. It contains :
● build.gradle (Project) : contains build scripts
defining all plugins that are used in the app.
● build.gradle (Module): contains plugins and
implementations are used to build
configurations that can be applied to all our
application modules. That is, target minimum
sdk, version name, version code and the list of
dependencies that are used in our app.
● And some other files.
DEMO
Thank you

Kotlin for Android App Development Presentation

  • 1.
    Kotlin for Android AppDevelopment Nadra Ibrahim, Rishika Kumari
  • 2.
    Lack of etiquetteand manners is a huge turn off. KnolX Etiquettes ▪ Punctuality Join the session 5 minutes prior to the session start time. We start on time and conclude on time! ▪ Feedback Make sure to submit a constructive feedback for all sessions as it is very helpful for the presenter. ▪ Silent Mode Keep your mobile devices in silent mode, feel free to move out of session in case you need to attend an urgent call. ▪ Avoid Disturbance Avoid unwanted chit chat during the session.
  • 3.
    Agenda 1. Why Kotlin? 2.Learning by doing • Softwares required • Develop a basic android app • Run on Emulator 3. Folder structure ❖ Manifest Folder • App Components • Intent • Intent Filters ❖ Java Folder • Activity • Activity Lifecycle ❖ Res Folder • Layout • Declare UI elements in XML • Load the XML resource ❖ Gradle scripts folder 1. Demo
  • 4.
  • 5.
    Kotlin Kotlin is ahigh level programming language developed by JetBrains in 2010. It was developed primarily to address the shortcomings of the Java programming language and to provide a modern, efficient, and safe alternative to it. Features: ● Open source, ● Easy to learn, ● Cross-platform, ● Statically-typed, concise and expressive, ● Interoperability with Java, ● Seamlessly Integrated with Android Studio, ● Null safety, ● No More NullPointerExceptions, ● has both object-oriented and functional constructs, ● Google’s Android Team has announced it as an official language for Android Application Development.
  • 6.
  • 7.
    Android Studio Android Studiois the official integrated development environment for Google's Android operating system, built on JetBrains' IntelliJ IDEA software and designed specifically for Android development. Emulator The Android Emulator simulates Android devices on your computer so that you can test your application on a variety of devices and Android API levels without needing to have each physical device. Physical device Connect your Android device to your computer via their USB ports and run the app in Android Studio on a physical Android device.
  • 8.
    Develop a basicandroid app • Install and open Android Studio. • New Project > Empty Views Activity. • Enter name of your project and package. • Select the location to save your project. • Select Kotlin as the language • Leave the minimum sdk as it is. • This will develop a default android app for you.
  • 9.
    Run on Emulator Theemulator comes with Android Studio, so you don't need to install it separately. Follow these basic steps : ● Verify that you have the required system requirements ● Go to device manager and select create device. ● Select your phone, then next. ● Choose system design, download it and finish. This will create a virtual device, that will run on Android studio. ● In the toolbar, select the AVD that you want to run your app on from the target device menu. And click run.
  • 10.
  • 11.
    Folder structure Contains anXML file which contains important metadata about the Android app. Contains source code and test files. Contains resources (for design). Contains the build configuration files for the project.
  • 12.
  • 13.
    Manifest Folder Every appproject must have an AndroidManifest.xml file, with precisely that name, at the root of the project source set., inside the manifest directory. This file is created for you and most of the essential manifest elements are added as you build your app. This file contains information about our application such as the Android version, metadata, states package for Kotlin file, and other application components. It acts as an intermediary between android OS and our application. Among many other things, the manifest file is required to declare the following: ● The components of the app, ● The permissions that the app needs in order to access protected parts of the system or other apps. It also declares any permissions that other apps must have if they want to access content from this app. ● The hardware and software features the app requires, which affects which devices can install the app from Google Play.
  • 14.
    App Components For eachapp component that you create in your app, declare a corresponding XML element in the manifest file.If you subclass any of these components without declaring it in the manifest file, the system can't start it. Specify the name of your subclass with the name attribute, using the full package designation. For example, To declare your activity, open your manifest file and add an <activity> element as a child of the <application> element.
  • 15.
    Intent App activities, services,and broadcast receivers are activated by intents. An intent is a message defined by an intent object that describes an action to perform, including the data to be acted on, the category of component that is expected to perform the action, and other instructions. Although intents facilitate communication between components in several ways, there are three fundamental use cases: ● Starting an activity ● Starting a service ● Delivering a broadcast There are two types of intents: ● Explicit intents specify which application will satisfy the intent, by supplying either the target app's package name or a fully-qualified component class name. ● Implicit intents do not name a specific component, but instead declare a general action to perform, which allows a component from another app to handle it.
  • 16.
    Intent Filters When anapp issues an intent to the system, the system locates an app component that can handle the intent based on intent filter declarations in each app's manifest file. The system launches an instance of the matching component and passes the Intent object to that component. If more than one app can handle the intent, then the user can select which app to use. An app component can have any number of intent filters (defined with the <intent-filter> element), each one describing a different capability of that component. You can take advantage of this feature by declaring an <intent-filter> attribute in the <activity> element. The definition of this element includes an <action> element and, optionally, a <category> element and/or a <data> element. This intent filter tells that this is a launcher activity, that is, it will be the first to open up.
  • 17.
  • 18.
    Java Folder The Javafolder contains all the java and Kotlin source code (.java) files that we create during the app development, including other Test files. There are multiple packages inside this directory : com.package.projectname : When we create any new project using Kotlin, by default the class file MainActivity.kt file is created automatically under the package name. test directory : This directory is for pure unit test that do not involve android framework. You can run tests here without running on a real device or on emulator. Android test directory : This directory is for unit tests that involves android instrumentation.
  • 19.
    Activity An Android apptypically consists of multiple activities that work together to provide a seamless user experience. Unlike traditional programming paradigms with a main() method, Android apps are built around the concept of components, and the Activity is a fundamental component. When one app invokes another, the calling app invokes an activity in the other app, rather than the app as an atomic whole. In this way, the activity serves as the entry point for an app's interaction with the user. An activity implemented as a subclass of the Activity class. An activity provides the window in which the app draws its UI. Generally, one activity implements one screen in an app. To use activities in your app, you must register information about them in the app’s manifest, and you must manage activity lifecycles appropriately.
  • 20.
    Activity Lifecycle The activityhas some predefined functions to handle the state changes in the application’s activity. Override the functions to achieve the required functionality when the activity’s state is being changed.
  • 21.
  • 22.
    Res Folder Contains allnon-code resources, such as UI strings and bitmap images, divided into corresponding subdirectories. res/drawable folder : contains the different types of images used for the development of the application. We need to add all the images in a drawable folder for the application development. res/layout folder : contains all XML layout files which we used to define the user interface of our application. It contains the activity_main.xml file. res/mipmap folder : contains launcher.xml files to define icons that are used to show on the home screen. It contains different density types of icons depending upon the size of the device such as hdpi, mdpi, xhdpi. res/values folder : contains a number of XML files like strings, dimensions, colors, and style definitions. One of the most important files is the strings.xml file which contains the resources. res/xml folder : contains arbitrary XML files that can be read at runtime.
  • 23.
    Layout A layout definesthe structure for a user interface in your app, such as in an activity. All elements in the layout are built using a hierarchy of View and ViewGroup objects. A View is defined as the user interface which is used to create interactive UI components such as TextView, ImageView, EditText, RadioButton, etc., and is responsible for event handling and drawing. They are Generally Called Widgets. A ViewGroup act as a base class for layouts and layouts parameters that hold other Views or ViewGroups and to define the layout properties. They are Generally Called layouts.
  • 24.
    Declare UI elementsin XML We can create a layout similar to web pages. The XML layout file contains at least one root element in which additional layout elements or widgets can be added to build a View hierarchy.
  • 25.
    Load the XMLresource When you compile your app, each XML layout file is compiled into a View resource. Load the layout resource in your app's Activity.onCreate() callback implementation. Do so by calling setContentView(), passing it the reference to your layout resource in the form: R.layout.layout_file_name. Generally, during the launch of our activity, the onCreate() callback method will be called by the android framework to get the required layout for an activity. Also we can access the UI element from the XML using findViewById.
  • 26.
  • 27.
    Gradle scripts folder Gradlemeans automated build system and it contains a number of files that are used to define a build configuration that can be applied to all modules in our application. It contains : ● build.gradle (Project) : contains build scripts defining all plugins that are used in the app. ● build.gradle (Module): contains plugins and implementations are used to build configurations that can be applied to all our application modules. That is, target minimum sdk, version name, version code and the list of dependencies that are used in our app. ● And some other files.
  • 28.
  • 29.