Android Flashcards

1
Q

What are the greatest challenges of Android development?

A

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

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

Not a question! Read the metaphor:

“Think of Android as a hotel”

A

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)

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

Which are App building blocks?

A

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

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

What component types does Android have?

A

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

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

What do you know about MVP architecture pattern

A

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

What ways of Creating and Laying out views do you know?

A

Graphically within Android Studio
XML Files
Programmatically

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

What is view?

A

basic building block for user interface components

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

View vs ViewGroup vs Layouts

A

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

How is user interface build in Android?

A

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.

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

What are the common operations you can do with Views?

A

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)

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

What happens when you load a layout resource in your app?

A

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.

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

What is the ID view?

Structure of it.

A

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

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

Geometry of a View (location, dimension, unit)

A

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.

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

Accessing Resources
Structure of resource ID
How can we access

A

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

Referencing style attributes - attr

A

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”

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

Context Definition.

Typical uses of context:

A

= current state of the application/object. It lets newly-created objects understand what has been going on.

Typical uses of context:
Loading a resource. (getString, getColor)
Launching a new activity. (startActivity)
Creating views.
obtaining system service (regarding content providers, broadcasts, intent)

17
Q

Application Context Activity Context

A

They are both instances of Context, but the application instance is tied to the lifecycle of the application, while the Activity instance is tied to the lifecycle of an Activity. The activity is simply providing the context needed by the view. Thus, they have access to different information about the application environment.

Example Use: If you have to create an object whose lifecycle is attached to an activity, you can use the activity context.

Get the context:
Context context = getApplicationContext();

An activity is its own context:
TextView myText = new TextView(this);
18
Q

Ways to get Context

A

You can get the context by invoking

  • — getApplicationContext(),
  • — getContext(),
  • — getBaseContext()
  • — this (when in a class that extends from Context, such as the Application, Activity, Service and IntentService classes).
19
Q

Resource files

  • Accesing Resource files
  • Resource qualifiers
A

Resource files are stored in folders located in the res folder, including:
> drawable: For images and icons
> layout: For layout resource files
> menu: For menu items
> mipmap: For pre-calculated, optimized collections of app icons used by the Launcher
> values: For colors, dimensions, strings, and styles (theme attributes)

20
Q

dp , sp, px

A
  • Device Independent Pixels (dp) - for Views
    - Scale Independent Pixels (sp) - for text
    Don’t use device-dependent units:
    - Actual Pixels (px)

Device-independent pixels (dp) are independent of screen resolution (used for views)
For example, 10px (10 fixed pixels) will look a lot smaller on a higher resolution screen, but Android will scale 10dp (10 device-independent pixels) to look right on different resolution screens.
Text sizes can also be set to look right on different resolution screens using scaled-pixel (sp) sizes.

21
Q

Style

A

A style is a resource that specifies common attributes such as height, padding, font color, font size, background color

22
Q

Responding to view clicks

A
  1. Add clickListener to button
  2. android:onClick=”showToast”

showToast() method must be public, return void, and require a view parameter in order to know which view called the method.

23
Q

Events, Event Handlers, Listener

A

Event : Something that happens
In UI: Click, tap, drag
Device: DetectedActivity such as walking, driving, tilting
Events are “noticed” by the Android system

Event Handlers: Methods that do something in response to a event
When the button itself will handle its touch event
Ex. in a custom button class, override: onTouchEvent(…)

Listener: if you want your activity to handle when someone touches the button, you use an event listener
btn.setOnTouchListener(…)

24
Q

String Resources - String, String array, Quantity Strings

A

String- XML resource that provides a single string.
text_string can include styling tags (format, html tags b,i,u)
text_string

String Array- XML resource that provides an array of strings.

    text_string

Quantity Strings (Plurals)- XML resource that carries different strings for pluralization

    Znaleziono %d piosenkę.
    Znaleziono %d piosenki.
    Znaleziono %d piosenek.

*quantity=[“zero” | “one” | “two” | “few” | “many” | “other”]

25
Q

Strong / Weak reference

A
A strong reference is an ordinary Java reference, the kind you use every day. For example, the code:
StringBuffer buffer = new StringBuffer();
As you don't want the garbage collector destroying objects you're working on, this is normally exactly what you want.

Aweak reference - is a reference that isn’t strong enough to force an object to remain in memory.
So you may find (if there are no strong references to the widget) thatweakWidget.get()suddenly starts returningnull.

26
Q

Style - Theme

A

So the difference is style attribute applies for just this view, theme – for this view and all its children.

27
Q

Manifest

A

1) application: Info about application (package,title, icon and theme) Also acts as a container that includes the Activity, Service, Content Provider and Broadcast Receiver tags for specifying the application components
- Node activity
name: class name
intent-filter : child tags which specify which
Intents launch the activity.
- Node service
- Node provider - content provider
- Node receiver - to register broadcasst receiver

2) uses-permission - the permissions you include will always be presented to the user to either grant or deny during installation. Ex. location services, SMS, internet