Week 3 Flashcards
What is an activity?
Activity class = entry point for app’s interaction with user, providing window btwn app + UI. Can be subclass of Activity class.
How many activities can there be?
If apps contain multiple screens, they have multiple activities. One activity is the designated ‘main activity’, which appears on launch.
Can activities launch other activities?
Yes, they are able to launch another activity to perform a specific function.
What are intent filters and when/how are they used?
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.
Explain:
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.
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);
This demonstrates how to call the activity.
How do you declare permissions?
Permissions are declared in the manifest’s tag. Note, a parent activity cannot launch a child activity unless they share the same permissions.
Explain:
, 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:
Explain this code:
to be allowed to call SocialApp, your app must match the permission set in SocialApp’s manifest:
What is the activity lifecycle and how can it be managed?
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
What does onCreate() do?
This callback fires when system creates activity. It initialises essential activity components and is always followed by onStart().
What does onStart() do?
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.
What does onResume() do?
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
What does onPause() do?
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.
What does onStop() do?
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.