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()
Describe an Activity ‘onStop()’ method?
Occurs when an activity becomes invisible to the user, and is the callback to release resources that aren’t needed. (ex. if registered a BroadcastReceiver in onStart() then unregister the receiver in the onStop())
What Activity callback method is called after onStop()?
onDestroy()
Describe an Activity ‘onDestroy()’ method?
It is the final call the activity receives. The system invokes this callback because the activity is finishing due to isFinishing() being called or the system destroys the process.
What is the purpose of the Activity ‘onDestroy()’ method?
To release all resources that have not yet been released.
What Activity callback is called when expecting a result from an Intent?
onActivityResult(int, int, Intent)
Can the android system destroy the process containing your activity to recover memory if the activity is in the Stopped state?
Yes, especially when it hasn’t been used in a long time, or if the foreground activity requires more resources.
If an Activity is destroyed by the system, and the user navigates back to the activity, how is previously destroyed state get stored?
instance state is a collection of key-value pairs stored in a Bundle object
What happens to an activity when a configuration change occurs?
The activity is destroyed and recreated.
What is a Task?
It’s a collection of activities that the users interact with when performing a certain job. (ex. using an application)
Does the Android system retain state of every activity in the task, when the task is in the background?
Yes, unless the android system needs to remove resources for memory.
When an activity is destroyed, the system does not retain the activity’s state?
True
What is the difference in life cycle between AsyncTask and a Loader?
An AsyncTask lives as longs as the task lives, the Loader lives as long as the activity that starts it. Loaders are tied to the activity life cycle.
How can you make a string resource untranslatable?
By setting attribute ‘translatable’ = false
Where should your application activities be declared?
AndroidManifest.xml file
How can you pass multiple parameters to AsyncTaskLoader?
By passing the extra parameters to the constructor