Intents Flashcards

1
Q

What is the role of intents?

A

Intents enable communication between components both within the same application and in system wide applications. Intents always provide some action to carry out.

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

Explain the difference between an implicit and explicit intent…

A

Explicit intents -> Used to activate other components within the same application. The name of the receiving component is explicitly given.
Implicit intents -> Name of receiving component is not given. Used to broadcast action to local and system wide components with compatible intent filters.

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

Talk through how an implicit intent works…

A

Implicit intent is created with relevant specifies Action, Data, Category, Extras etc. and is sent to the Android Management System.
The AMS searches through system-wide manifests for components with compatible intent filters.
An app chooser is presented to the user with all the compatible applications that can carry out the intent action.

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

How to we ensure that an app chooser is shown, rather than the system automatically completing the action with a default applicaiton.

A

Call the createChooser( ) method.

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

What makes an intent explicit?

A

A Component Name.

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

When building an implicit intent, what is the Data added for?

A

To give a reference to the URI object that is going to be acted on. For example, a URL.

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

How do we set intent filters to capture implicit intents?

A

Within the components tags in the manifest, specify intent-filter tags, within which specify action, data and category tags.

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

What are the 7 intent fields?

A

Name, Data, Action, Category, Flag, Extra, Component.

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

Define what the Action, Category, Type, Flag fields do.

A

Action -> Define the action the receiving component should do.
Category -> The category of the component that should handle the intent.
Type -> Indicates the MIME type of the intent data.
Flags -> Specifies how the intent should be handled.

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

How do we ensure that there is at least one match for the implicit intent?

A

Use resolveActivity( ) with the package resource manager and ensure it doesn’t return null.

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

What intents can be received by an activity with no intent-filters?

A

Explicit intents.

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

How would you launch an activity for a result?

A

Use ActivityResultLauncher to register an activity for the result. Then use this launcher to launch the intent.

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

In Android Development, what are contracts? Give an example of a contract…

A

A contract is a class that defines several methods that are used to enable communication between different components. For example, an instance of ActivityResultContracts gives access to all methods that enable communication between a launching activity and the responding activity.

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

What are the 4 main contract classes?

A

ActivityResultContracts -> Methods aide communication between launching activity and responding activity.
Permission Contracts -> Defined set of actions for requesting and handling permissions.
Intent Sender Contracts -> Defines set of methods for sending an intent to another component.
Activity Result Registry Contracts -> Defines a set of methods for registering / unregistering activity request callbacks.

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

Which callback is used to respond to an ActivityResultLauncher? What data does this result hold?

A

ActivityResultCallback is a functional interface with a onActivityResult method, within which the result can be interacted with.
The result holds the request code (if set), the data, the result code.

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

What are the 3 fundamental use cases of intents?

A
  • Starting an activity
  • Starting a service
  • Delivering a broadcast
17
Q

What is the R class? What is its structure?

A

The R class contains all resource ID’s of all resources in the application.
It contains inner classes for each type of resource, and each inner class consists of static integers that represent the resource ID’s of each project resource of that type.