Intents Flashcards

1
Q

What is an intent?

A

An intent is a way to perform tasks between separate activities in the runtime environment. For example, you may run an intent to obtain data from another ‘form’ activity.

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

How can we create an intent to traverse between activities?

A

We instantiate a new Intent, and give it the context of both the Activity it is inside, and the Activity we need to be sent to.

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

How can we send data between activities using intents?

A

We include ‘extras’ to our intent. Extras are like little data snippets we can send alongside our intent, which can be accessed from within the new activity as long as it has the resultant Intent object.

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

What is the different between an explicit and an implicit intent?

A

Within an explicit intent, we define exactly which component we want to start. We specify which component by using its class name. This is typically done to start components from within the same app.

An implicit intent, however, does not specify the exact component. Instead, we define an action or data of some kind, which gives the user a list of where to send the data. This is mostly used for inter-app communication, such as - for example - sharing text from social media to an email app.

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

What is an intent field?

A

Each ‘intent field’ is a different way to use an implicit intent.

For example, we can define an Action, which tells us what we want the resultant app to do. Or, we can define a type in MIME format, which tells the OS what the data is.

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

What is the use of the Category intent field?

A

Category is used to define what category of component should handle the intent. For example, CATEGORY_LAUNCHER.

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

What is the use of the Flag intent field?

A

Flag is used to specify how an event should be handled. For example, FLAG_ACTIVITY_NEW_TASK may point to an application’s ability to push a new task to its database.

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

What happens if more than one app can handle the Intent?

A

Either we can write code to define that ourselves, or a chooser dialog will appear, allowing the user to decide for themselves.

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

How do we define what implicit intents an activity can receive?

A

We can define this within <intent-filter> in the Android manifest file. It is like a firewall, and we can 'whitelist' certain intent types that our activity can handle.</intent-filter>

e.g. <action></action>
The above will be able to handle Intent.ACTION_EDIT implicit intents.

You can do the same for MIME types with <data android:mimeType … />

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

What is the purpose of the intent filter?

A

It is a sort of whitelist that allows activities to accept certain implicit intents from other apps. For example, an email composer may allow EDIT intents, or VIEW intents.

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