Lecture 3 Flashcards
What are the four different types of components?
Activities - single screen
Services - background processes
Broadcast receivers - to subscribe to events in the android operating system
Content providers - e.g databases
What is the point of a component?
Entry point through which the system or user can enter the app
What are Intents?
Allows an app to call a component from another app
What is an Activity?
Entry point for interacting with the user
Single screen with an interface
Can be launched by other apps is the containing app allows it
What interactions between system and app do activities faciliate?
Tracking user activity (what they are doing)
Tracking previously used processes and content and allowing user to resume
Allowing apps to flow between each other
What is the most important component type?
Activity
When an Activity is launched, what processes are called?
onCreate() -> onStart() -> onResume()
When is onPause() called?
When the activity needs to pause but still be visible, e.g. a semi transparent dialog or window covers it
When a resumed activity is closed, what processes are called?
onPause() -> onStop() -> onDestroy()
When is an activity stopped?
When another Activity is launched. E.g. new window or closing the app
What happens to an Activity when the screen is rotated?
Activity is destroyed then Recreated
State of any view components is retrieved and re-instantiated though
What 6 states can an Activity be in?
Created
Started (visible)
Resumed (visible)
Paused (partially visible)
Stopped (hidden)
Destroyed
When should you save any important information?
Frequently and immediately if possible!
onPause and onStop should be used to save non-critical state info
How do apps run with relation to the linux-like architecture of Android?
Each app is separate linux user with its own VM. Can only access its own files
Which component doesn’t exchange Intents?
Content providers
Why are intents used instead of direct method calls?
Allows other components to be started
access can be controlled by OS
Where must all components be registered?
AndroidManifest.xml
How do you start a new Activity?
Define a class that sub-classes Activity
Add some GUI control to invoke from parent Activity
Listen for the relevant GUI event, then launch a new Intent
What are the two types of Intent? What’s the difference?
Explicit and Implicit
Explicit: specifies exactly which Activity should be started
Implicit: Explains what the activity should do (eg a web browser) - system then finds the most appropriate
What is the back stack?
Collection of activities that users interact with
Each opened Activity is added to the back stack when it is opened
When the user presses the back button, the Activity is ended and popped off the stack
How can you have multiple instances of the same activity within an app on the back stack?
if activities in that app can be instantiated from multiple places
How can the back stack behaviour be modified?
Attributes in <activity> manifest element and flags in startActivity()</activity>
Can do things like clear back stack of all activities from that app except the root activity, or bring forward an existing activity