Android Development Flashcards
What are the 4 types of app components?
Activities.
Services.
Broadcast receivers.
Content providers.
What is an Activity lifecycle?
https://developer.android.com/reference/android/app/Activity.html
Launched -> onCreate -> onStart -> onResueme -> Running -> onPause -> onStop
onPause -> onResume
onStop -> Killed or onStop -> onRestart
What is an Intent?
A messaging object you can use to request an action from another app component.
What are the three fundamental use cases of an intent?
- starting an activity
- starting a service
- delivering a broadcast
Should an implicit intent be used when starting a service?
No
Why should you use an explicit intent to start a service?
Security reasons, and if an implicit intent is used, your app doesn’t have control of which service will respond to the intent. (API 21+) throws exception if using an implicit intent on call ‘bindService()’
What are the main component of building an Intent?
Component name, Action, Data, Category, Extras, Flags
How do components receive intents?
Declaring one or more intent filters for each of the app components with an element in the manifest file.
Which three tests must a intent filter pass for implicit intent to use that component?
Action test, Category test, Data test
Can you declare multiple per component?
Yes
Which object has a set of query methods that will return all components that accept a particular intents? (by checking components )
PackageManager
What class serves ass the entry point for an app’s interaction with the user?
Activity class
Where must you declare activities that will be used in your application?
in the manifest file.
What is the only required attribute for declaring an activity in the manifest?
android:name attribute
Which Activity callback method is called when the system first creates the activity?
onCreate()
What should be performed in the onCreate method of an Activity?
Basic application startup logic, (example, bind data, initialize background threads, instantiate class-scope variables).
Describe an Activity ‘onStart()’ method?
Prepares the activity to enter the foreground and become interactive. (ex. app initializes code that maintains UI, or register a BroadcastReceiver that monitors changes that are reflected in the UI).
Describe an Activity ‘onResume()’ method?
When this method is executed, activity enters foreground, and is the state in which the app interacts with the users. (Initialize components that are released during ‘onPause()’).
When does the Activity leave the onResume state?
When the app loses focus.
What Activity method is called when the app loses focus?
onPause()
Describe an Activity ‘onPause()’ method?
Execution is very brief, and does not afford enough time to perform save operations or any long operation.
What Activity method should be used for ‘heavy-load’ shutdown operations?
onStop()
Once an Activity is in the ‘onPause()’ state, how long does the activity remain in the ‘onPause()’ state?
Until either the activity becomes completely invisible to the user, or if the activity resumes, and the system invokes the ‘onResume()’ method.
When an Activity is no longer visible to the user, what method is invoked?
onStop()