Android app structure Flashcards

1
Q

What is the structure of Android app?

A

Typical Android app is consisting of:
- Program code
- Resource files
* XML files
* Images and additional files (audio etc.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Android philosophy?

A

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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Where are located Resource XML files?

A

Resource XML files are located in separate part of
project, in res folder.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

On which format relies Dalvik VM?

A
  • 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between Dalvik and ART?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In which programming language are Android apps written?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How look Java libraries?

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is APK?

A

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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Android Manifest?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How Android app is built in Java?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is Activity?

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the lifecycle of an Activity?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is Activity Manager?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is important in Activity Lifecycle?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is Layout XML file?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What defines Layout XML file?

A
  • Which components are visible in UI
  • What are the visual attributes of those components
  • How components are placed on the screen
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Where is located Layout XML?

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are String resources?

A
  • Strings visible in UI are also resources which should
    be kept in separate resource file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Where we keep string resources?

A

File where we keep string resources is usually called
strings.xml and it is located in res/values folder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Where we can define string resources?

A
  • Strings can be defined directly in app (hardcoded in
    activity class or layout file), however it is not good
    practice
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What can contain string resource?

A
  • String resources file can contain strings and string arrays (string-array elements)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How strings can be defined?

A
  • Strings are defined as <string> tags, with name attribute which can later be used for access to the string and value between open and closed string tag</string>
23
Q

How we can reference resources, and through what the resource is referenced?

A
  • It is possible to reference resources inside layout file from different resource files
  • String resources are referenced through @string directive
24
Q

For what referencing resources is used?

A
  • Resources are referenced in order to set attributes of View component
25
Q

What is R.java class?

A
  • R.java class enables easy programmatic access to resources
26
Q

How R.java is generated?

A
  • It is generated automatically by the environment
27
Q

Why Programmer should use R.java class?

A
  • Programmer should not use hard coded resource values, but should use R.java class instead for accessing resources in the code.
28
Q

How the content of this class should be changed?

A

Programmer should not manually change content of this class.

29
Q

What contains R.java class?

A

R.java contains integer constants which enable access to:
* layout files
* string resources
* colors, dimensions …

30
Q

What happens when Android starts application?

A
  • When Android starts application, it finds main Activity class, creates instance and calls onCreate() method
    • Template Method Pattern
31
Q

What happens inside onCreate() method when Android starts application?

A

Inside onCreate() method, Activity should prepare display, and call method setContentView() which takes a View which should be displayed:

  • As a int value from R.java class - recommended
  • As a View object if view is created programmatically – not recommende
32
Q

What is GUI?

A
  • Graphical user interface refers to all things showed
    on screen in order to perform interaction with user
33
Q

On what we should pay attention when we are working with GUI?

A

When working with GUI, you should pay attention
to:
* Setting attributes
* Setting event listeners
* Setting focus on some elements
* Displaying components

34
Q

What are classes View and ViewGroup?

A
  • Main components of UI in Android
  • ViewGroup and View components make hierarchy
    in UI
35
Q

How components (View and ViewGroup) can be defined?

A
  • This components can be defined programmatically
    (dinamically) or in layout XML file (recommended)
36
Q

How Android provides access for this components?

A

For View components defined in XML layout file, Android provides easy way of accessing them in Activity class code:
* By using R.java class

37
Q

What is View component?

A
  • View component is object which draws something on the screen, and we can interact with it

*It is geometrical surface that can react to events.

38
Q

What is ViewGroup component?

A
  • ViewGroup component is object which can contain number of components (View and ViewGroup), in order to define layout on the UI
39
Q

What is View class?

A
  • View class is the superclass of all graphical component in Android

*For example, EditText component which is used to display a text field is a subclass of View class

40
Q

What are some of the frequently used View subclasses?

A
  • TextView - label
  • EditText – text field
  • Button
  • CheckBox
  • ImageView - image
  • ImageButton – image which is used as button
  • RadioButton
  • ProgressBar – progress indicator
  • ViewGroup classes …
41
Q

What is ViewGroup class?

A

ViewGroup is also a subclass of View class

42
Q

For what are used ViewGroup components?

A
  • ViewGroup components are used to group other
    View components
43
Q

What are some of the frequently used ViewGroup components?

A
  • LinearLayout
  • RelativeLayout
  • GridLayout
  • ListView
44
Q

How the location of every component is defined?

A
  • Pair of starting coordinates (x and y define top left corner)
  • Two dimensions, width ad height
45
Q

How dynamic determination of a component of type View can be achieved?

A

For a component of type View, dynamic determination of starting coordinates can be achieved by calling methods getLeft() and getTop(), which return relative position to the parent component

*Methods for getting right bottom corner: getRight() and getBottom()
* getRight () = getLeft() + getWidth()

46
Q

What is Padding?

A
  • Padding is a space between component border and
    component content
47
Q

What is Margin?

A

Margins are space between component and
neighbor components

48
Q

What is Layout declaration?

A
  • Static declaration of UI using XML
49
Q

How Android enables development of UI interface?

A
  • Attributes are directly translated from XML to
    appropriate View classes and subclasses
50
Q

Is declaration of UI possible during the runtime?

A
  • Declaration of UI during runtime is possible, by
    declaring and setting up components
    programmatically
51
Q

How an XML element is named?

A

Name of an XML element matches the name of the View class which needs to be drawn
* Element <TextView> create instance of class TextView on UI
* Element <LinearLayout> create instance of class LinearLayout for grouping other elements</LinearLayout></TextView>

52
Q

What Android initializes when loading layout to some application?

A
  • When loading layout to some application, Android initializes every node in hierarchy into object accessible during runtime
  • These objects can be accessed from the code during
    runtime
53
Q

How XML declaration is achieved?

A
  • Every layout must have exactly one root element, which is either View or ViewGroup
54
Q

What should have an XML layout atribute?

A
  • ID – every view has an associated integer ID
  • During compilation, this id is referenced as an
    integer value, and it is typically set as a String in
    XML layout file
  • Identifier is set as an attribute android:id of the
    corresponding View XML element