Android Flashcards
What are the greatest challenges of Android development?
Multiple screen sizes and resolutions
Performance: make your apps responsive and smooth (ex. services when needed, to save battery)
Security: keep source code and user data safe
Compatibility: run well on older platform versions
Marketing: understand the market and your users
Not a question! Read the metaphor:
“Think of Android as a hotel”
Your app is the guest
The Android System is the hotel manager
Services are available when you request them (intents)
In the foreground (activities) such as registration
In the background (services) such as laundry
Calls you when a package has arrived (broadcast receiver)
Access the city’s tour companies (content provider)
Which are App building blocks?
Resources: layouts, images, strings, colors as XML and media files
Components: activities, services, …, and helper classes as Java code
Manifest: information about app for the runtime
Build configuration: APK versions in Gradle config files
What component types does Android have?
Activity is a single screen with a user interface
Service performs long-running tasks in background
Content provider manages shared set of data
Broadcast receiver responds to system-wide announcements
What do you know about MVP architecture pattern
The MVP- well-established way to group app functions:
- Views. Views are user interface elements that display data and respond to user actions. Every element of the screen is a view. The Android system provides many different kinds of views.
- Presenters. Presenters connect the application’s views to the model. They supply the views with data as specified by the model, and also provide the model with user input from the view.
- Model. The model specifies the structure of the app’s data and the code to access and manipulate the data.
What ways of Creating and Laying out views do you know?
Graphically within Android Studio
XML Files
Programmatically
What is view?
basic building block for user interface components
View vs ViewGroup vs Layouts
View is the base class for widgets, it is an object that draws something on the screen that the user can interact with. (buttons, text fields, etc.).
Views can be grouped together inside a view group (ViewGroup), which acts as a container of views. The relationship is parent-child, (ScrollView, RecyclerView)
Some ViewGroups are designated as layouts because they organize child views in a specific way and are typically used as the root view group.
» LinearLayout: A group of child views positioned and aligned horizontally or vertically.
» RelativeLayout: each child view is positioned relative to other views
» TableLayout: child views arranged into rows and columns.
» AbsoluteLayout: A group that lets you specify exact locations (x/y coordinates) of its child views. Absolute layouts are less flexible and harder to maintain
» FrameLayout: child views are drawn in a stack, with the most recently added child on top. The size of the FrameLayout is the size of its largest child view.
» GridLayout: A group that places its child screens in a rectangular grid that can be scrolled.
How is user interface build in Android?
All user interface elements in an Android app are built using View and ViewGroup objects. A View is an object that draws something on the screen that the user can interact with. A ViewGroup is an object that holds other View (and ViewGroup) objects in order to define the layout of the interface.
What are the common operations you can do with Views?
Set properties: for example setting the text of a TextView.
Set focus: To force focus to a specific view, call requestFocus().
Set up listeners: Views allow clients to set listeners that will be notified when something interesting happens to the view.
Set visibility: You can hide or show views using setVisibility(int)
What happens when you load a layout resource in your app?
When you load a layout resource in your app, Android initializes each node of the layout into a runtime object you can use to define additional behaviors, query the object state, or modify the layout.
What is the ID view?
Structure of it.
Views may have an integer id associated with them
Are used to find specific views within the view tree
View IDs need not be unique throughout the tree, but it is good practice to ensure that they are at least unique within the part of the tree you are searching.
@[+][package:]type/name
TO ADD : android:id=”@+id/my_button”
+id means new id must be created and added to our resources (in the R.java file).
TO REFERENCE: android:id=”@android:id/empty”
With the android package namespace in place, we’re now referencing an ID from the android.R resources class, rather than the local resources class.
*@ - at-symbol
Geometry of a View (location, dimension, unit)
The geometry of a view is that of a rectangle. A view has a location, expressed as a pair of left and top coordinates, and two dimensions, expressed as a width and a height. The unit for location and dimensions is the pixel.
Accessing Resources
Structure of resource ID
How can we access
When your application is compiled, aapt generates the R class, which contains resource IDs for all the resources in your res/ directory. For each type of resource, there is an R subclass (for example, R.drawable for all drawable resources), and for each resource of that type, there is a static integer (for example, R.drawable.icon). This integer is the resource ID that you can use to retrieve your resource.
Structure:
type(string, drawable, layout) +
name(filename, string resource)
How can access:
- In code: Using a static integer from a sub-class of your R class, such as: R.string.hello
- In XML: @string/hello
- string is the resource type and hello is the resource name.
Referencing style attributes - attr
A style attribute resource allows you to reference the value of an attribute in the currently-applied theme.
To reference a style attribute, the name syntax is almost identical to the normal resource format, but instead of the at-symbol (@), use a question-mark (?), and the resource type portion is optional. For instance:
?[:][/]
For ex, can reference an attribute to set the text color to match the “primary” text color of the system theme:
android:textColor=”?android:textColorSecondary”
explicitly would be: “?android:attr/textColorSecondary”