Week 3 Flashcards

1
Q

What is an activity?

A

Activity class = entry point for app’s interaction with user, providing window btwn app + UI. Can be subclass of Activity class.

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

How many activities can there be?

A

If apps contain multiple screens, they have multiple activities. One activity is the designated ‘main activity’, which appears on launch.

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

Can activities launch other activities?

A

Yes, they are able to launch another activity to perform a specific function.

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

What are intent filters and when/how are they used?

A

Intent filters provide the ability to launch an activity based on explicit request, or implicit request. E.g. ‘Send email activity in Gmail app’ = explicit. E.g. ‘Start a send email screen in any activity that can do the job’

This can be done by declaring an in element.

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

Explain:

A

In this example, the element specifies that this activity sends data. Declaring the element as DEFAULT enables the activity to receive launch requests. The element specifies the type of data that this activity can send.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
Explain:
// Create the text message with a string
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, textMessage);
sendIntent.setType("text/plain");
// Start the activity
startActivity(sendIntent);
A

This demonstrates how to call the activity.

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

How do you declare permissions?

A

Permissions are declared in the manifest’s tag. Note, a parent activity cannot launch a child activity unless they share the same permissions.

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

Explain:

A

, if your app wants to use a hypothetical app named SocialApp to share a post on social media, SocialApp itself must define the permission that an app calling it must have:

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

Explain this code:

A

to be allowed to call SocialApp, your app must match the permission set in SocialApp’s manifest:

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

What is the activity lifecycle and how can it be managed?

A

The activity lifecycle is when the activity goes through changes over its lifetime. It can be managed by a series of callbacks to handle transitions between states:
onCreate(), onStart(), onResume(), onPause(), on Stop(), onRestart(), onDestroy

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

What does onCreate() do?

A

This callback fires when system creates activity. It initialises essential activity components and is always followed by onStart().

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

What does onStart() do?

A

After onCreate() exits, and activity enters ‘Started’ state, activity becomes visible to user. Callback contains activity’s final preparations for coming to foreground and becoming interactive.

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

What does onResume() do?

A

Invokes callback before activity interacts with user. Currently, activity is at top of activity stack & captures user input. Core functionality is implemented in onResume() method

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

What does onPause() do?

A

System calls onPause() when activity activity loses focus & enters Paused state. e.g. when user taps Back / Overlay button. Means that activity still technically partially visible. E.g. navigation map/ media player.

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

What does onStop() do?

A

System calls onStop() when activity no longer visible to user. Activity could be destroyed, new activity could be starting or existing activity entering a Resumed state.

Next callback = onRestart() or onDestroy if terminating.

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

What does onRestart() do?

A

System invokes callback when activity is in Stopped state & going to restart. Restores state of activity from time it was stopped.

17
Q

What does onDestroy() do?

A

Destroys activity. Implemented to ensure all of activity’s resources are released when activity/ process containing it, is destroyed.