Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
58 Cards in this Set
- Front
- Back
what 3 steps event-wise happen when a button is clicked in android? |
1. button clicked 2. android system receives the event 3. only the LISTENER is interested in reacting to the event e.g. when the doorbell rings, everyone hears it, but only the person interested runs to the door |
|
what are the 4 steps to implement button click? |
1. tell android system we're interested in listening to button click - implement onClickListener 2. retrieve button from xml into java code - findViewById 3. tell java we're listening to button being clicked - button.setOnClickListener(this); 4. what should happen when button is clicked - in the onClick method |
|
what is a view? what's an example? |
object that occupies a rectangular area on screen is responsible for handling events e.g. button, text |
|
what is a view group? what are its different types of structures? |
occupies rectangular area on screen, is invisible and holds other views in a certain structure (vertically, horizontally, grid) |
|
what is the root view? in the root view, what should the width and height be set to? |
the top-level ViewGroup that holds all the other ViewGroups/Views width/height should be match parent to fill up all available space |
|
when you assign a layout_weight to 1, what does it do to the other elements that have layout_weight of 0? |
the ones with 0 take up only the space it NEEDS, and heavier one will take up the rest of the space |
|
what's the difference between layout_gravity and gravity? |
layout_gravity controls the place where the VIEW is situated in the layout (inside the parent) gravity controls where the CONTENT of the view (inside) should appear inside the view -> e.g. how the text is aligned in the component |
|
for layout_gravity: horizontal layout will not change the ___ vertical layout will not change the ___ |
horizontal layout will not change the column vertical layout will not change the row |
|
when does gravity attribute doesn't really work, in terms of its width and height? |
when width/height is wrap_content |
|
what are 2 advantages of a listview? |
- can display large amounts of data - manages data for displays on devices of various sizes |
|
what are the 3 concepts of ListView? |
1. large amount of data (data source e.g. array, database) 2. class to manage the data (ListAdapter) 3. class to manage the appearance (ListView) |
|
what does ListAdapter do? |
takes item from data source and create a view out of it e.g. text view, image and a text view |
|
what does the adapter in android do? what are examples of adapters? |
- responsible for managing the data - adapter accesses the data and displays it in a view different types of adapters - array adapter - cursor adapter (database) - base adapter (custom data |
|
what are intents? what do they allow? |
asynchronous messages allow android components to request functionality from other components of the android system, AND other activities in the app |
|
what's another function of intents other than its main? |
can also be used to single system that a certain event has occured |
|
how can other components register to an event, to know if a certain event has occurred? |
intent filter |
|
what are 3 examples of components that intents can communicate with, and send data, and receive responses? |
activity service broadcast receiver |
|
how to send an intent to the system to start aNOTHER activity? 2 lines of code |
Intent i = new Intent(this, ActivityTwo.class); startActivity(i); ActivityTwo.class is its FULL java name |
|
what are the two types of intents? |
explicit intent = defining the component which should be called by android system, using java class identifier implicit intent = specify action which should be performed and can start ANY component that can handle the intended action -> action is a filter |
|
why would you use an implicit intent? give an example |
in the app, if you want to send an email, specify the ACTION and leave it up to the system that can do that functionality another example: google maps |
|
how to send data with explicit intents? code |
i.putExtra("key", value); |
|
what's the line of code to start an implicit intent? |
Intent i = new Intent(Intent.ACTION_VIEW); |
|
what's a typical thing that's registered to Intent.ACTION_VIEW? |
web browser |
|
what happens after the android system searches for the components that are registered for an action, when you do implicit intents? |
if only one component found, it's started directly if there's several components, user will get selection dialog |
|
when you send an intent to the android system, what do you need to specify? |
which type of component the intent should be sent for example activity or service |
|
what intent is used when you send a user to another app? |
implicit intents |
|
how to verify there is an app to receive your intent? |
PackageManager.queryIntentActivities() |
|
what does queryIntentActivities() return? when should you do this check? |
list of activities capable of handling the intent if list is not empty, intent can be safely used check when activity first starts |
|
which method to retrieve result data from the started activity? |
startActivityforResult(i, REQUEST_CODE) which is an intent method |
|
what does REQUEST_CODE do? why is it important? |
identifies the intent important if you're making an intent for more than one activity |
|
how to return data to the initial activity that made an intent for you? |
in void finish() setResult(RESULT_OK, data); data parameter is the bundle of data that you putExtra() things into |
|
what is result code? |
RESULT_OK or RESULT_CANCELED |
|
what are 3 categories of sensors? give examples |
motion sensors e.g. accerometer, gravity sensor, rotational sensor environmental sensors e.g. air temperature sensors, pressure, light position sensors e.g. physical position, orientation |
|
what are virtual sensors? what's an example |
they are calculated result of calculation from other sensors rotation sensor is an example |
|
what are 5 guidelines when accessing hardware |
1. no assumption that hardware exist 2. always check and verify optional features 3. exception handling and errors 4. return value checking 5. hardware features are device resources, so: - acquire late, release early - don't drain battery by misusing hardware resources |
|
what does the SensorManager class do? |
create an instance of the sensor service |
|
what does the Sensor class do? what does it provide? |
create an instance of a specific sensor methods that let you determine sensor's capabilities |
|
what does the SensorEvent class do? what does an sensor event object incude? |
system uses this class to create sensor event object which provides info about a sensor event |
|
what does an sensor event object include? 4 things |
raw sensor data type of sensor that generated event accuracy of data timestamp for event |
|
what sensorEventListener interface do? |
use this interface to create two callback methods that receive notifications (sensor events) when sensor values change |
|
what are 2 sensor related tasks? |
identifying sensors and sensor capabilities - disable app features that use sensors that are not present on device - identify all sensors of a given type and choose one with optimum performance for app monitor sensor events - acquiring sensor data (event_ every time sensor detects change - gets the things from sensor event object |
|
what are the 4 steps when working with sensors? |
1. see what sensors are available on device 2. determine sensor's capabilities (e.g. max range, power requirements, etc.) 3. acquire raw sensor data and define minimum rate where you acquire data 4. register and unregister sensor event listeners that monitor sensor changes |
|
when we identify sensors and capabilities, how do we do that in the code? 2 steps |
get instance of sensormanager private SensorManager mSensorManager; mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); get list of all sensors on the devices List deviceSensors = mSensorManager.getSensorList(Sensor.TYPE_ALL); |
|
how to check for a certain sensor in code? |
after getting system service: if(mSensoranager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null) { // we have one } |
|
what are the two methods from SensorEventListener interface? |
onAccuracyChanged() onSensorChanged() |
|
what do you have to put in manifest to use services like power service, vibration service, etc.? |
permissions |
|
when do you need to set layout_width to be 0? what about layout_height to 0? |
when you use layout_weight in a view inside a horizontal linearlayout, set layout_width to 0 when you use layout_weight in a view inside a vertical linearlayout, set layout_height to 0 |
|
in horizontal linearlayouts, ___ and ___ directions work for layout_gravity in vertical linearlayouts, ___ and ___ directions work for layout_gravity |
horizontal = top and bottom / row vertical = right and left / column |
|
what does an adapter look like in code? |
ArrayAdapter adapter = new ArrayAdapter(this, androidlayoutthing, datasource); |
|
what interface do you have to implement when you want to use listviews? |
AdapterView.OnItemClickListener(); |
|
what method comes with the OnItemClickListener interface, what are the parameters, and what do you do with it? |
onItemClick(AdapterView<?>parent, View view, int position, long id); 1 = listview parent 2 = view that was clicked (textview) 3 = row of view that was clicked, starting from 0 4 = id of data |
|
what method is called (in activity1) when activity2 sends back its results to activity1? |
onActivityResult(int requestCode, int resultCode, Intent data); 1 = requestCode identifies which activity, it was passed to startActivityForResult() 2 = RESULT_OK or RESULT_CANCELED 3 = result data |
|
in activity2, how do you send results back to activity1? what is the method and what is the actual method where you set the result? |
public void finish(){ Intent data = new Intent(); data.putExtra("returnKey1", ”This is the result"); // Activity finished ok, return the datasetResult(RESULT_OK, data); super.finish(); } |
|
what does the power service give us? how does that help us? |
gives us information about the power of the system helps us because it's crucial to use battery wisely |
|
with services such as power, wifi, telephony etc, what is the line of code to use them? |
SomethingManager manager = (SomethingManager) getSystemService(Context.SOMETHING_SERVICE); |
|
what does the alarm service do? |
Fires an Intent in the future |
|
what does connectivity service do? what 2 things does it check? |
check device network state checks WIFI, GRPS and connection changes |
|
what can wifi service do? 3 things |
- lists all the configured wifi connections - scan for wifi network - check/edit wi-fi connection |