Android app structure Flashcards
What is the structure of Android app?
Typical Android app is consisting of:
- Program code
- Resource files
* XML files
* Images and additional files (audio etc.)
What is Android philosophy?
Android philosophy – decouple code and resource files
* Resource files – XML files which define layouts, dimensions, colors, fonts, themes…
- Code is written in Java, using Android API libraries, together with some default Java libraries
- Android allows programmer to access elements defined in resource files from the code, and make changes to display, handle events etc.
Where are located Resource XML files?
Resource XML files are located in separate part of
project, in res folder.
On which format relies Dalvik VM?
- Dalvik VM expects different bytecode than
standard Java class files – it rely on it’s own format,
Davlik Executable (DEX). - Android platform contain set of tools for
postprocessing complied Java class files to DEX
format. - Standard Java applications usually contain several
class files – DEX merges all class files to unique DEX
file.
What is the difference between Dalvik and ART?
Since Android 5 – only ART VM is used
* Major difference between ART VM and Dalvik VM –
ART during installation translates large portion of
executable byte code to machine native language,
so subsequent application runs don’t need
complete .dex translation to machine languag
In which programming language are Android apps written?
Most of the Android apps are written in Java, so we will
focus only on Java
However, there are different options:
* Some code parts can be written in C/C++ in order to maximize performances, or if OpenGL is used for 3D
animations
* Kotlin can also be used
* Parts of the app can be written as HTML, CSS and
JavaScript, and packed to Android application
How look Java libraries?
Java libraries for Android are similar to Java SE
version
- Difference – Java libraries for GUI (AWT and Swing)
are not available, Android specific libraries are used
instead. - Android adds additional functionality to standard
Java – location, sensors, WiFi, phone and
messaging
What is APK?
APK are ZIP archives, similar to JAR format (but not the
same).
APK (Android Package) file contain 3 major
components:
* Java code compiled to Dalvik executable
* Resources (everything which is not a code)
* Optional source C/C++ files
- In order to be installed on device, Android apps must
be signed (self-signed certificate can be used also)
What is Android Manifest?
This file contains information required by the system:
* App name, package name, app version
* Minimum API version required for app
* App components declaration
* Required permissions
* Libraries which app needs in order to run
All Android apps have AndroidManifest.xml file in root
directory!
How Android app is built in Java?
Android app in Java is built by extending classes from predefined Android classes.
Additionally, we create metadata which will inform Android about the classes.
Extended classes are called components in Android terminology, and there are 4 types:
* Activities
* Services
* Content providers
* Broadcast receiver
What is Activity?
It is Basic UI block.
- Analog to the web page in
web app - Usually covers most of the
screen, leaving place for
clock, battery indicator
and similar notifications - App usually has several activities, and user moves forward and backward between them
- Similar to the web application, which typically has several web pages
- Web site has home page – Android app has main activity, this is the activity which is displayed when app is run
- Similar to web site, Android app must provide navigation
What is the lifecycle of an Activity?
Starting an activity can be expensive in terms of
resources:
* Starting new Linux process
* Allocating memory for all UI objects
* Creating object from XML layout
* Setting the screen
Since activity start is expensive, it would not be wise to
discard it when user leaves the screen
Therefore, Activity Manager controls activity life cycle
What is Activity Manager?
- Responsible for creating, destroying and managing
activities - When user runs app for the first time, Activity Manager will create activity and show it on the screen
- Later, when user switch screen, Activity Manager will move current activity in storage, from where it will call it faster again if needed
- Older activities, which have not been used for some
time, will be destroyed to make space for current
activities
What is important in Activity Lifecycle?
- Programming Android app is more focused on
reacting to the state changes in application, than
on triggering those changes - It is managed, container based environment similar
to servlet programming for Java Web apps - When we talk about activity lifecycle, it is not
important to know in which state activity is, but
there are ways to regulate what happens during
transitions between different states
What is Layout XML file?
Every Activity class, together with program code, should have defined visual appearance of UI
Defining of visual appearance can be done in two ways:
* Programatically – not recommended
* Layout XML file - recommended
What defines Layout XML file?
- Which components are visible in UI
- What are the visual attributes of those components
- How components are placed on the screen
Where is located Layout XML?
Layout are located in folder res/layout
One activity class has one associated layout file
- Good practice is to match name of layout file with
name of activity class - For HelloWorldActivity layout file could be named
hello_world_activity.xml, activity_hello_world.xml or
slično
What are String resources?
- Strings visible in UI are also resources which should
be kept in separate resource file
Where we keep string resources?
File where we keep string resources is usually called
strings.xml and it is located in res/values folder
Where we can define string resources?
- Strings can be defined directly in app (hardcoded in
activity class or layout file), however it is not good
practice
What can contain string resource?
- String resources file can contain strings and string arrays (string-array elements)