Professional Documents
Culture Documents
XML in Android
by
Zana Azeez Kakarash
Email: zana.azeez@kti.edu.krd
2021 – 2022
Two
XML in Android
• XML tags are not predefined in XML , we must define our own Tags.
• XML as itself is well readable both by human and machine , also, it is scalable and simple to develop.
• In Android we use XML for designing our layouts because XML is lightweight language so it doesn’t
make our layout heavy.
1. XML is a very popular and widely-used format. Hence, a lot of developers are quite comfortable with it.
2. It helps to provide separation of the UI from the code logic. This provided flexibility to change one
3. Generating XML output is easier than writing direct code, making it easier to have drag-and-drop UI
• A markup language prepare a structure for the data or prepare the design of a page.
• The whole concept of Android User Interface is defined using the hierarchy of View and ViewGroup
objects.
• These child views are other widgets which are used to make the different parts of UI.
• Here in above Diagram ViewGroup (Linear Layout) contains one ViewGroup (i.e. Relative Layout) and
two View (Button and TextView)
9
Different XML Files Used in Android
• In Android there are several xml files used for several different purposes.
• Layout xml files are used to define the actual UI (User interface) of our application.
• It holds all the elements (views) or the tools that we want to use in our application. Like
• It includes the names of our application packages, our Activities, receivers, services and the
• Example Suppose we need to use internet in our app then we need to define Internet permission in
this file.
• This xml file is used to replace the Hard-coded strings with a single string.
• We define all the strings in this xml file and then access them in our app(Activity or in Layout XML files)
4 - Styles xml File(styles.xml): This xml is used to define different styles and looks for the UI(User
Interface) of application.
5 - Drawable xml Files: These are those xml files that are used to provide various graphics to the
elements or views of application.
20
Where to Run Android App
e. Return to the previous screen, scroll to the bottom, and tap Developer options.
f. In the Developer options window, scroll down to find and enable USB debugging.
• 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.
• Step 1: Firstly, open the AVD Manager directly by the AVD icon in the Toolbar.
• Step 2: Your Virtual Devices list will be opened on your Computer screen. After that you Select that
AVD on which you want to run your App.
• Android SDK tools compile code, data and resource files into Android PacKage (filename.apk).
a) App elements
b) User Interface
c) Other code designed to run in background
27
Android Compilers
• Your source code is compiled by Standard Java Compiler which uses the JIT- 'Just-In-
• The bytecode gets executed by target-specific-VM , which is a runtime environment for Java.
- ART
1) The Java Compiler (javac) converts the Java Source Code into Java Byte-Code (.class).
2) Then DEX Compiler converts this (.class) file into in Dalvik Byte Code i.e. “.dex” file.
3) Dalvik Virtual Machine uses its own byte-code and runs “.dex” (Dalvik Executable File) file.
• ART was introduced in Android 5.0 (Lollipop), ART completely replaced Dalvik.
• ART as the runtime executes the Dalvik Executable format and Dex bytecode specification.
• Uses the ahead-of-time compilation model which compiles the apps to machine code upon installation.
• Apps run a bit FASTER! under ART, so the startup time of apps gets reduced.
• You will need SDK (Software Developer Kit) to compile the Java code of your application.
• Your code and precompiled classes from runtime and custom libraries are compiled.
• The next step is to take the output files from step number 2 and to turn those files into dex bytecode -
Dalvik EXecutable(.DEX)
• The DEX bytecode is a format that is optimized for Android and which can be executed by the older
• Note : It generate a .apk file from a DEX file + non-Java libraries + zipped resources.
• The classes.dex file and the resources from your application, such as images and layouts, are then
compressed into a zip-like file called an Android Package or .apk file.
35