Activities Flashcards

1
Q

How are Android apps launched and how does this differ from other programming paradigms.

A

Unlike programming paradigms in which applications are launched with a main() method, the Android system initiates code in an Activity instance by
invoking specific callback methods that correspond to specific stages of its lifecycle.

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

Discuss activities as entry points for a use to an app and give an example

A

● Android application’s interaction does not always begin from an implied point the way traditional desktop and other apps do.
● Instead, an apps initial point is usual non-deterministic,
depending on the context f it’s launch, e.g, when launched
from a different app, the specific activity being called is what
launches
● When one app invokes another, the appropriate activity is usually launched, and not the app as an atomic whole.
● Therefore, an activity acts as an entry point for a use to the
app

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

How are activities implemented?

A

An activity is implemented as a subclass of the Activity class.

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

Define windows and screens in Android in relation to activities

A

An activity provides the window in which the app draws its UI.
● This window typically fills the screen, but may be smaller than the screen and float on top of other windows.
● Generally, one activity implements one screen in an app.
● An app has one main activity, which is the first screen that
appears when an app launches.

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

Define an activity in the manifest with all the required attributes

A

● To declare your activity, open your manifest file and add an <activity> element as a child of the <application> element.</application></activity>

<manifest … >
<application … >
<activity></activity>

</application … >

</manifest >

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

Describe intent filters

A

Intent filters provide the ability to launch an activity based
not only on an explicit request, but also an implicit one.

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

Give examples of implicit and explicit requests

A

Sample explicit: “start a send message activity using WhatsApp”
● Implicit: “start a send message activity using an app able to do it on the phone”

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

Give an example of an intent filter in the manifest

A

<activity>
<intent-filter>
<action></action>
<category></category>
<data></data>
</intent-filter>
</activity>

page 7

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

Write code to call an activity with an intent

A

val sendIntent = Intent().apply {
action = Intent.ACTION_SEND
type = “text/plain”
putExtra(Intent.EXTRA_TEXT, textMessage)
}
startActivity(sendIntent)

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

Describe permissions and how they are handled across activities

A

● Permissions control the access different apps have for various
activities and content.
● To grant access to a given content or activity, the corresponding permissions need to be declared.
● In cases where we have parent and child activities, to enable
the parent class launch the child class, similar permissions need to be declared in both activities to ensure compliance.

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

Describe how permissions will be handled in a situation where an app wants to use another app

A

if an 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:

//Declaration in the SociaApp:

<manifest>
<activity android:name="...."
android:permission=”com.google.socialapp.permission.SHARE_POST”
/>

//Declaration in the app that calls the activity in SocialApp
<manifest>
<uses-permission></uses-permission>
</manifest>
</manifest>

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

List all the callbacks in the android life cycle

A

onCreate()
onStart()
onResume()
onPause()
onStop()
onRestart()
onDestroy()

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

Describe onCreate()

A

● A must callback in any activity
● Executes when system creates activity.
● Initializes essential activity components, eg, views and data binding
● setContentView() is called here to define activity’s UI layout
● Always precedes the onStart() activity

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

Describe onStart()

A

● Always succeeds onCreate()
● Makes activity visible to the user

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

Describe onResume()

A

● Invoked just before activity starts user interaction
● Usually done when the particular activity is at the top of the activity stack, thus captures data (user input)
● Implements most of the app’s core functionality
● Always precedes the onPause()

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

Describe onPause()

A

● Effects when activity loses focus, eg, on clicking “Back” or “Recent apps”
● Put’s activity on partial visibility but is a precursor to stopped ot resume states
● Should not be used to: save app/user data, make network calls or execute DB transactions
● Precedes either onStop() or onResume()

17
Q

Describe onStop()

A

● Called when activity is no longer visible to the user because:
– It has been destroyed
– New activity is starting
– Paused activity is resuming and covers the stopped activity
● Precedes onRestart() or onDestroy()

18
Q

Describe onResart()

A

● Invoked when a stopped activity is about to restart
● Restores activity from time it was stopped
● Always succeeded by onStart()

19
Q

Describe onDestroy()

A

● Invoked before activity is destroyed
● Final callback for an activity
● Releases activity’s resources (security and preservation purposes)