• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/267

Click to flip

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;

267 Cards in this Set

  • Front
  • Back

whats earlier mobile?

- a piece of stone/clay with markings


- Papyrus scroll & ink pen


- 1800s: printed book

whats the mobile platforms?

- The Brick: 1983 Motorola


- Apple Newton 1987: vision leading for today, PDA(Personal Digital Assistant)


- Marco, Envoy: 1995 Motorola

whats the form factors?

- handheld large devices


- palm-sized

what is the role of Telecommunication Industry?

- combined PDA features with networked applications
- clam shell design; qwerty keyboard
- came out in 2007 (birth year of iPhone)

- combined PDA features with networked applications


- clam shell design; qwerty keyboard


- came out in 2007 (birth year of iPhone)

what are some initial innovations?

1. lower power mobile processors


2. higher quality displays:


- promising future as gaming & multimedia capable devices


- eased the disappearance of the hardware keyboard


- evolution to multi-touch screens

what are some initial technologies?

1. low power, meter accuracy GPS technologies that enabled and fueled location based services




2. embedded sensors that optimize the platform operation (compass, proximity & acceleration) and provides higher level services to users (camera, light)

what is the software architecture?



what is android?

- mobile operating system + app framework




Google


- develops & extends the Android OS


- distributes the android OS and developer tools


- runs Goolge Play (Android app market)

what type of devices can Android run on?

multi-platform


- android wear: watches


- android tv: apps, games


- android auto: entertainment & navigation

android versions

the Android Architecture

- operating system is based on Linux that is specifically designed to be run on mobile devices

- complete application framework allows us to create & deploy our own custom apps

1. Linux Kernel
2. Libraries & Android runtime
3. Application Framew...

- operating system is based on Linux that is specifically designed to be run on mobile devices




- complete application framework allows us to create & deploy our own custom apps




1. Linux Kernel


2. Libraries & Android runtime


3. Application Framework


4. Applications

Android Architecture : Linux Kernel

Linux itself & set of drivers


eg: audio, camera, display, keypad, power

Android Architecture : Libraries + Android runtime

- set of core libraries built in C++


eg: graphics, databases




- virtual machine that run in its own box

Android Architecture : application framework

modules for controlling different components of an app




eg: activities(screen), content providers (mange data, move data between apps), location, notifications

what is part of Application Components?

1. activities


2. services


3. broadcast receivers


4. content providers

Application Components : activities

- screens: made up of views


- multiple views arranged into layouts

Application Components : services

-perform a background job


- usually do not have a visual component

Application Components : broadcast receivers

- react to system messages


- react to messages from other apps

Application Components : content providers

- managed access to data


- apps exchange data with each other

what is Android Studio?

new Android development environment based on IntelliJIDEA

Android Development Environment: android studio

- emulator


- virtual device manager


- android device monitor(DDMS)


- interface of android studio


- logcat

Android Studio : Emulator

a virtual device that display the software version of device




pros: conveniently test app on various hardware/screen sizes




cons: missing features/hardware for sensing GPS, camera, video recording

Android Studio : AVD manager

Android Virtual Device Manager

Android Virtual Device Manager





Android Studio : Android Device Monitor(DDMS) debug

stand-alone tool that provides a graphical user interface for several Android application debugging & analysis tools

Android Studio : LogCat debug

log message at runtime with Log class for debugging

uses memory & CPU resources

log message at runtime with Log class for debugging




uses memory & CPU resources

Android project structure

- manifest: app name, app activities
- java code: programming logic
- resource folder

- manifest: app name, app activities


- java code: programming logic


- resource folder





what is an activity?

an application component that provides a screen




an app can have many screens/activities, with one main activity

why is the lifecycle important?

know if the activity is visible to user, paused/stopped

know if the activity is visible to user, paused/stopped

activity life-cycle (methods)

onCreate, onStart, onResume: launch app for the first time

onPause, onStop: move from one activity to another activity

onRestart, onStart, onResume: back button 

onDestroy: kills activity due to low memory, manually finish the activity

onCreate, onStart, onResume: launch app for the first time




onPause, onStop: move from one activity to another activity




onRestart, onStart, onResume: back button




onDestroy: kills activity due to low memory, manually finish the activity

Activity life-cycle states

device orientation changes

every time the device orientation changes, the activity life-cycle is destroyed & recreated




the system will automatically save its instance state in a bundle object





saving the activity state & restore

consider what the state is the activity in when orientation changes




although the activity has been paused, stopped and destroyed, and then recreated, after orientation change, all information should be kept




- onSaveInstanceState()


- onRestoreInstanceState()


* although these are called automatically by system, it is good to add Log to keep track

onSaveInstanceState

- save temporary information, variable values before calling onPause


- triggered right after onPause

onRestoreInstanceState

- restore temporary information, variable values


- triggered right after onStart

Back Button exception

when back button is pressed, Android system assumes that the activity is no longer needed, and destroy it, information cant be restored

Bundle variable

provide key (unique id) with value for temporary data




*same Bundle is received after the activity is been restored after destroying

what is context?

interface to global information about an application environment

using application context

how to retrieve application context?

using Contextcontext = getApplicationContext();

how to retrieve application resources?

using getResources() with a resource's identifier (ID)




Stringgreeting = getResource().getString(R.string.hello);

how to access application preferences?

using getSharedPreferences() to retrieve simple application data

what is app resources?

resources defined by the developer within the Android project files and are specific to the application

resources defined by the developer within the Android project files and are specific to the application

what is system resources?

it is common resources defined by the Android platform and accessible to all applications through the Android SDK

it is common resources defined by the Android platform and accessible to all applications through the Android SDK

how to accessing application resources?

can be accessed programmatically using the generated classfile called R.java with getResources()

how to access system resources?

access by (android.R.string) for words such as OK, Cancel, Yes, No, Cut, Copy & Paste

what are simple resource values?

1. /res/values/strings.xml - display text




2. /res/values/colors.xml - applied to screen controls




3. dimensions

other types of resources

- string array


- menus


- animation sequences


- shape drawables


- style & themes


- custom layout controls

UI controls : button & button click event

when button clicked, Android system receives the event, only the listener is interested in reacting to the event

when button clicked, Android system receives the event, only the listener is interested in reacting to the event

UI controls : view structure

view structure : view

object, occupies a rectangular area on screen & is responsible for handling events (TextView, EditView, etc)

view structure : view group

occupies rectangular area on screen, is invisible & holds other views in a certain structure (vertically, horizontally, grid, ect)

UI controls : linear layout

xml: all Views & ViewGroups are placed in 1 ViewGroup which is the root of the View hierarchy

orientation: 2 modes
-horizontal same column
-vertical same row

xml: all Views & ViewGroups are placed in 1 ViewGroup which is the root of the View hierarchy




orientation: 2 modes


-horizontal same column


-vertical same row

linear layout : root view

width & height usually set to match_parent, to fill up all available space

linear layout attributes : layout_weight

2 components: any values >= 1, as long as the other component does not have a value for layout_weight

2 components: any values >= 1, as long as the other component does not have a value for layout_weight

linear layout attributes : layout_weight

more components: decide the priority/importance of 1 component vs. the other

more components: decide the priority/importance of 1 component vs. the other

linear layout attributes : layout_gravity

controls the place where the view is situated in the layout (outside of the view)

*will not change the column/row

controls the place where the view is situated in the layout (outside of the view)




*will not change the column/row

linear layout attributes : gravity

controls where the contents of the view should  appear inside the view

*no effect if wrap_content

controls where the contents of the view should appear inside the view




*no effect if wrap_content

UI controls : ListView

ListView Concept

ListView Concept

ListView : creating

What is the use of Adapter?

it manages the data by accessing the data and display it in a view (ListView, GridView, Spinner, etc)

how many types does adapter have?

adapter types are related to data source



1. array adapter: data from array




2. cursor adapter: data from cursor(database)




3. base adapter: custom data

what is Intents?

asynchronous messaging mechanism that allow Android components to request functionality from other components of the Android system

asynchronous messaging mechanism that allow Android components to request functionality from other components of the Android system

what is Explicit Intents?

it explicitly define the component name which should be called by the Android system, by using the java class as identifier

it explicitly define the component name which should be called by the Android system, by using the java class as identifier

what is Implicit Intents?

it specify the action which should be performed

it specify the action which should be performed, & it can start any component that can handle the intended action

what happens when there are many components registered for a specific action and the data type in implicit intents?

it searches for all components that are registered for the specific action and the data type




- one component found: it is started directly




- several component: the user will get a selection dialog and can decide which component should be used for the intent

how do start other components using intent?

activities: startActivity(Intent);




services: startService(Intent);

sending user to another app

it depends on the action (view, edit, send) and intents often include data, might be Uri (address, email message)

how to put extra data in intent?

putExtra()

* if there is no Uri, declare "text/plain"

putExtra()




* if there is no Uri, declare "text/plain"

verification if there is app to receive your intent

queryIntentActivities():


returns a list of activities able to handle the action intent




* check before starting the activity

how do you retrieve result data from called activity?

retrieve by calling startActivityforResult() using REQUEST code, after startActivity() is called




the onActivityResult on the sending activity is called

what is request code?

this is the argument that identifies the request for the result




*maps the returning result from intent

result code

result code is specified by the second activity


RESULT_OK: if operation was successful


RESULT_CANCELED: operation failed

sending data/result to initial activity

onActivityResult(request code, result code, result data)

how do you receive data?

by checking the request code & result code, then use getExtra()

what is the process to receive intent?

1. create intent: setting up startActivityResult




2. prepare the result to send back (packaging)




3. returning the result: check if the result is okay with request code

how to use intent filters?

be specific what to filter:


- type of action (ACTION_SEND, ACTION_VIEW, etc)


- data the activity accepts

what are the types of built in sensors?

1. motion sensors


2. environmental sensors


3. position sensors

what data can you get from sensors?

raw data, high precision & accuracy

motion sensors

- acceleration, forces, rotational forces along 3 axes




- accerometers, gravity sensors, rotational vector sensors, gyroscopes

environmental sensors

ambient air temperature sensors, pressure, illuminations, humidity

position sensors

- physical position of the device




- orientation sensors, magnetometers

what are the guidelines when accessing hardware?

check if the device have the sensor to be used first, check at onResume & release the activity after checking

check if the device have the sensor to be used first, check at onResume & release the activity after checking

Android Sensors Framework

1. SensorManager


2. Sensor


3. SensorEvent


4. SensorEventListener

sensor related tasks : identifying sensors & sensor capabilities

- disable app features that use sensors that are not present on the device




- identify all sensors of a given type & choose the one with optimum performance for your app

sensor related tasks : monitor sensor events

- acquiring sensor data, sensor event, every time a sensor detects a change in parameter




- name of sensor that triggered the event, time-stamp, accuracy of event raw sensor data that triggered the event

what is the process for working with sensors?

1. determine which sensors are available




2. determine an individual sensor's capabilities




3. acquire raw sensor data




4. register sensor event listener at onResume, unregister at onPause

how to identify sensors & capabilities?

get a reference to the sensor device & get an instance of the SensorManager class:


private SensorManager mSensorManager;


...


mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);




then get a listing of every sensor on the device:


ListdeviceSensors=mSensorManager.getSensorList(Sensor.TYPE_ALL);

checking for certain sensor

monitoring sensor events : onAccuracyChanged

accuracy changes, provides a reference to the Sensor object that changed, and the new accuracy value




called whenever the accuracy of a given sensor changes

monitoring sensor events : onSensorChanged

sensor reports a new value, new data, sensor that generated the data, timestamp, accuracy of data




called whenever the values of the sensor change, inspect sensor information

adding sensors in manifest

indicates which sensors are required by the application

indicates which sensors are required by the application

acquiring a reference to a sensor

using getDefaultSensor in the SensorManager class to acquire raw sensor data

using getDefaultSensor in the SensorManager class to acquire raw sensor data

rate of sensor data

the rate might be high depending on what sensor is used




processing data should not be done in onSensorChanged

how to determine device orientation with sensor?

getOrientation of the SensorManager class takes 2 parameters:




rotation matrix & an array of 3 float values (azimuth[z], pitch[x], roll[y])

list of system services available

- Power service


- keyGuard service


- Vibration service


- Alarm service


- Sensor service


- Audio service


- Telephony service


- Connectivity service


- Wi-fi service

system service : power

gives information about the power of the system




PowerManager pm=(PowerManager)getSystemService(Context.POWER_SERVICE);

system service : vibration

manages the vibration service




Vibrator vibrator=(Vibrator)getSystemService(Context.VIBRATOR_SERVICE);




*need android.permission.VIBRATE

system service : alarm

fires an Intent in the future




AlarmManager as=(AlarmManager)getSystemService(Context.ALARM_SERVICE);





system service : telephony

interacts with calls




TelephonyManager tm=(TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);

system service : connectivity

check device network state




String serld = Context.CONNECTIVITY_SERVICE;


ConnectivityManager cm=(ConnectivityManager)Context.getSystemService(serld);

system service : wi-fi

manages the wi-fi connection




WifiManager wfm=(WifiManager)getSystemService(Context.WIFI_SERVICE);




- check/edit wi-fi connection


- scan for wi-fi networks


- be notified about wi-fi changes

what is temporary storage?

data storage that is stored in the device temporarily when the app is opened, the data will be removed after the app is closed

what is persistent storage?

data storage that is stored in the device even after the app is closed, unless the data is been cleared/uninstalled

what are some persistent data storage options?

1. SharedPreferences


2. Internal Storage


3. external storage


4. SQLite Database


5. Network Connection

persistent data storage : SharedPreferences

simple primitive data stored as key/value pairs that is private to the app

simple primitive data stored as key/value pairs that is private to the app

persistent data storage : internal

it save files directly on the device's internal storage that contains private files, if the app is uninstalled, files are removed

persistent data storage : external

the data is readable by anyone since it is stored in a removable storage media (SD card) that have non-removable internal storage

persistent data storage : SQLite database

structured data that is private to the app

structured data that is private to the app

what are SharedPrefs?

a simplest way of storing data in Android-XML file, it store the value & use the corresponding key to retrieve the value later

a simplest way of storing data in Android-XML file, it store the value & use the corresponding key to retrieve the value later

what kind of data can be stored in SharedPref?

only primitive data type, not complex data:


- boolean


- long


- int


- float


- string

how do you access the preferences?

public SharedPreferences getPreferences(int mode)

public abstract SharedPreferences getSharedPreferences(String name, int mode)

public SharedPreferences getPreferences(int mode)




public abstract SharedPreferences getSharedPreferences(String name, int mode)

modes in preferences

why should preferences be used?

what is the steps of storing data using sharedPrefs?

1. get a reference to the SharedPreferences object getPreferences/getSharedPreferences




2. call the editor edit()




3. use the editor to add the data with a key putBoolean(), putString(), etc




4. commit editor changed commit()

how to view SharedPrefs file?

data/data/< package-name > /shared-prefs

what are SQLite?

language for managing data in relational databses

what are the characteristics of SQLite database?

apps have their private SQLite databases that is accessible by any class in the app, but not by other apps




the database is self-contained, transaction-based, & there is no server

process of programmatically create database

whats the steps of creating an SQLite database schema?

1. define scheme : database name, version, table names, column names




2. create the database : queries to create the database




3. execute queries : insert, update, delete operations

how does SQLiteOpenHelper work?

implement onCreate() & onUpgrade()



-opens the database if it exists


- creates the database if it does not exist


- updates the database as necessary

SQLiteOpenHelper : onCreate

this method is called when the database is first created (creation of tables, initial data inside of tables)

SQLiteOpenHelper : onUpgrade

this method is called whenever the database is updated (drop, add tables, anything that updates the database structure)

SQLiteDatabase class

an object representing the database that we have just created

why nothing happens after you define the schema and created the database?

cause the database only gets created when you attempt to access it for the first time, where onCreate & onUpgrage is not been called when there is no access to the database

how do you access the database?

getWritableDatabase() will return an SQLite database object, a reference to the database that was just created

getWritableDatabase() will return an SQLite database object, a reference to the database that was just created

insert query for SQLite

creating an object of class ContentValues, it takes a key & a value

creating an object of class ContentValues, it takes a key & a value

what is the database code structure?

have code that is re-usable & keep separate UI code from database code

database code structure : Database class

contains a SQLite database instance & helper

database code structure : MyHelper class

extends the SQLiteOpenHelper class that provides methods for creating & updating the database (onCreate & onUpgrade)

database code structure : Constants class

hold all the string constants (table name, column names, etc), that will be used in both Database & MyHelper classes

how to read data from SQLite database?

query() pass the selection criteria &  desired columns

result from the query are returned in a Cursor object

query() pass the selection criteria & desired columns




result from the query are returned in a Cursor object

what is a Cursor object?

it gives us access to the results returned from a database query & allows navigation through the result




*android.database.Cursor

select query with condition

add new method to retrieve from the database in Database class

add new method to retrieve from the database in Database class

how do you link database data to the UI?

create a new activity & use SimpleCursorAdapter to link

what is a SimpleCursorAdaptor?

an easy adapter to map columns from a cursor to TextViews/ImageViews defined in XML 

an easy adapter to map columns from a cursor to TextViews/ImageViews defined in XML

whats the advantage of using SimpleCursorAdapter?

dont need to process the data from the cursor, just need to indicate which columnsare displaying into the UI controls 

  with the ID column 

dont need to process the data from the cursor, just need to indicate which columnsare displaying into the UI controls with the ID column

what is a process?

an executing instance of an application that run in their own memory space

what is a thread?

threads share the same memory space & several threads can be associated with 1 process

Process & threads in Android

we can arrange for different components in the app to run in separate processes & create additional threads for any process

we can arrange for different components in the app to run in separate processes & create additional threads for any process

how to decide which process has higher priority?

the process that the user is interacting at that moment  have higher priority

the process that the user is interacting at that moment have higher priority

which process is terminated first?

process with lowest importance is terminated first

what processes have highest importance with respect to the user?

1. foreground processes have the highest priority

2. visible process: activity on onPause & service bound to a visible activity

3. service process: no direct user interaction & service running (eg: playing music)

4. background process: no use...

1. foreground processes have the highest priority




2. visible process: activity on onPause & service bound to a visible activity




3. service process: no direct user interaction & service running (eg: playing music)




4. background process: no user interaction at all & the app most recently seen by the user is the last one to be destroyed




5. empty process: no active component running & still alive for caching purposes



process ranking

-foreground processes have the highest priority


- empty process is terminated first


- a service is ranked higher than a process that does not have a service




* its better to use a service for long-running operations, rather than performing long-running operations in a thread

multithreading in Android

every process has a main thread

every process has a main thread

what is the role of the main thread?

- the UI elements is updated


- clicking a button sends a message


- startService() and service code is processes

whats the effect does long running operation have on main thread?

the app appears to be frozen whcih the UI thread will be blocked, no events/drawing events can be dispatched while the main thread is trying to process the long running operations

what is UI thread?

main thread of execution

how to avoid blocking the UI/main thread?


how to improve responsiveness in main thread?

avoid performing blocking operations on the UI/main thread

avoid performing blocking operations on the UI/main thread

what is ANR?

when long operation is not responding, "Application Not Responding" dialog appears

whats StrictMode in the UI thread?

a developer tool which detects things you might be doing by accident (catch accidental disk/network access on main thread) & brings them to attention so you can fix it

AsyncTask

complete tasks asynchronously & communicate back to the main UI thread

whats the purpose of AsyncTask use in main thread?

handle events from different Views & components

whats the purpose of AsyncTask use in ActivityManager & WindowManager?

monitor the application for responsiveness

whats the purpose of AsyncTask use in each task?

if it takes more than 5 second, the ANR dialog is triggered

in what situation should AsyncTask be used?

its good for tasks lasting between 100ms to a few seconds, not more than a few second




* for longer tasks: use services

whats some limitations of AsyncTask?

not suitable for tasks longer than a few seconds, & it will not execute successfully as Android may kill those thread under critical considtions

why should we use Asyntask?

its easier to implement in comparison to thread & handler




it manage message queues, updating on progress & create/terminate background thread automatically

how can we implement AsyncTask?


whats the steps for implementing AsyncTask & where is it triggered?

- onPreExecute() runs on UI thread before background processing begins

- doInBackground(Param...params) runs on a background thread & won't block UI thread

- publishProgress(Progress...values) method invoked by doInBackground triggers call to o...

- onPreExecute() runs on UI thread before background processing begins




- doInBackground(Param...params) runs on a background thread & won't block UI thread




- publishProgress(Progress...values) method invoked by doInBackground triggers call to onProgressUpdate() on UI thread




- onPostExecute(Result result) runs on UI thread once doInBackground is done

steps of implementing AsyncTask - methods

what kind of parameter is provided to AsyncTask?

Param: type of parameter sent to the task for exercution




Progress: type of info used to indicate progress




Result: type of the result received from the background task

important notes about AsyncTask

- AsyncTask class must be loaded on the UI thread




- the task instance must be created on the UI thread




- execute() must be invoked on the UI thread




- onPreExecute, onPostExecute, doInBackground, onProgressUpdate are called automatically, don't call them in code

whats services?

app component that complete long-running operations in the background & no UI




another app component can start a service & the service will continue to run in the background even if the user switches to another app




another app component can bind to a service & interact with it

whats some uses of service?

whats the types of service?

1. started


2. bound




*can also have a started service (to run indefinitely) that allows binding

types of service : started

- started by an app component startService()




- runs in the background *even if the component that started it is destroyed




- single operation




- does not return a result to a caller

types of service : bound

- app bind to it: bindService()




- client-server interface: send requests/get result




- runs only as long as a component bound to it?

where does the service run?

it runs in the main thread of its hosting process




*service does not create its own thread/run in a separate process

creating a service

how is the service created and destroyed?

service lifecycle: it can run in the background without the user being aware

service lifecycle: it can run in the background without the user being aware

started service: classes to extend

whats the steps of creating a service?

1. create a class to extend service




2. declare the service in Manifest




3. override the onCreate & onDestroy




4. override the onBind




5. activate the service from an external trigger

how is the service behaving?

- doesn't stop when the activity is destroyed (change screen orientation)




- doesn't stop when the activity is paused (press the home button)




- runs as its own entity

whats a fragment?

stand alone parts/block of UI

whats the characteristics of fragment?

1. small component/portion/chunk of UI




2. has its own lifecycle




3. can process its own events




4. can be added/removed while activity runs





why do we use fragments?

- combine several fragments in a single activity with flexibility & dynamic UI design




- different layouts for different screen space size portrait/landscape

whats the steps for creating fragment?

1. create class for fragment (extend Fragment class)




2. provide layout (appearance) for fragment in xml




3. override onCreateView() to link the layout to the Java class from step 1




4. use the fragment in XML (static bound to UI) / java (dynamic - preferred approach)

whats the fragment lifecycle?

1. fragment as a java object when we first created

2. active that is running & linked to the activity

3. destruction

1. fragment as a java object when we first created




2. active that is running & linked to the activity




3. destruction

how does fragment lifecycle relate to activity lifecycle : fragment creation?

*activity start first, fragment then follows

onAttach: after the fragment is associated with the activity, it get a reference to the activity object

onCreate: do not access UI objects, activity onCreate may not be completed yet

onCreateView: l...

*activity start first, fragment then follows




onAttach: after the fragment is associated with the activity, it get a reference to the activity object




onCreate: do not access UI objects, activity onCreate may not be completed yet




onCreateView: link javs with xml & return view for fragment




onActivityCreated: called after onCreate has completed, ready to access/modify UI elements

how does fragment lifecycle relate to activity lifecycle : fragment destruction?

* fragment first, activity follow

onSaveInstanceState: used to save info inside a Bundle object

onDestroyView: destroy the view after the fragment view hierarchy is no longer asccesible

onDestroy: fragment is completely destroyed, it is still ...

* fragment first, activity follow




onSaveInstanceState: used to save info inside a Bundle object




onDestroyView: destroy the view after the fragment view hierarchy is no longer asccesible




onDestroy: fragment is completely destroyed, it is still an object attached to the activity, but not usable




onDetach: fragment is untied from activity

how to add fragment to activity?

1. XML approach


2. Java approach (preferred)

adding fragment approach : XML

static association of fragment with activity




* < fragment >

adding fragment approach : Java

its a dynamic approach & the fragment is added at run-time in response to user interaction using Fragment Manager

whats the role of Fragment Manager?

it uses getFragmentManager() to maintain references to all fragments inside the activity

*retrieve ID(XML-findFragmentById())

tag(Java-findFragmentByTag())

it uses getFragmentManager() to maintain references to all fragments inside the activity




*retrieve ID(XML-findFragmentById())




tag(Java-findFragmentByTag())

how is transactions processed in fragment?

perform changes on several fragments at the same time, where the changes can be included in the same transaction

perform changes on several fragments at the same time, where the changes can be included in the same transaction

how do you begin a transaction?

call the add method on the transaction:

transaction.add(R.id.Myout, frag, "Fragment2");

transaction.commit();

call the add method on the transaction:




transaction.add(R.id.Myout, frag, "Fragment2");




transaction.commit();

Fragment transaction

- either process with everything/nothing

- remove fragment (to be removed) first, then bring in new fragment

- either process with everything/nothing




- remove fragment (to be removed) first, then bring in new fragment

why is communication between fragments needed?

user performs some interaction on Fragment , which will lead to some event happening in Fragment 2

user performs some interaction on Fragment , which will lead to some event happening in Fragment 2

whats the rules of communication between fragments?

do not maintain references of 1 fragment within another fragment, interface is needed

do not maintain references of 1 fragment within another fragment, interface is needed

interfaces in java

it is standardized & contain methods with no body, so no implementation




it cannot create object of an interface but it can declare variable for an interface type

whats webview?

a view that displays web pages

*basis for creating your own web browser/display online content inside of activity

a view that displays web pages




*basis for creating your own web browser/display online content inside of activity

how can webview be used?


how do you handle URL Requests?

provide a WebViewClient for your Webview, using setWebViewClient()

provide a WebViewClient for your Webview, using setWebViewClient()

what are web services?

web services are means of exposing an API over a technology-neutral network endpoint

whats JSON?

Java Script Object Notation




a way to represent JavaScript objects as Strings & alternative to XML for passing data between servers and clients

what data does web service return?

XML/JSON strings

what does JSON format build on?

build on a collection of name-value pairs (objects, records, structs, etc) and an ordered list of values (array)

build on a collection of name-value pairs (objects, records, structs, etc) and an ordered list of values (array)

what form can JSON values take in?

whats the steps of accessing and capturing data from web service?

1. check the network connection




2. perform network operation on a separate thread - setup separate thread




3. connect & connect data




4. convert data from network into a target data type

how to check the network connection?

why should network operation be performed on a separate thread?

to avoid unpredictable delays that provide poor user experience

how do you setup separate thread for network operation?

using AsyncTask 

using AsyncTask

how do you perform network access?




how do you connect and download data from web service?

use HTTP to send & receive data 

use HTTP to send & receive data

whats Apache HttpClient?

it requires minimal code for simple HTTP processing that is stable and have very few bugs




*but not recommended

whats HttpURLConnection?

a lightweight client member of the package java.net that process the requests & responses (other classes from the package java.io)




*perfectly suited for use with web services

whats the step and the usage of HttpURLConnection?

1. obtain a new HttpURLConnection by calling URL.openConnection() & casting the result to HttpURLConnection




2. prepare the request




3. transmit data by writing to the stream returned by getInputStream()




4. read the response. The response body may be read from the stream returned by getInputStream(). If the response has no body, that method returns an empty stream




5. Disconnect. Once the response body has been read, the HttpURLConnection should be closed by calling disconnect(). Disconnecting releases the resources held by a connection so they may be closed/reused

what is Android Touch Framework?

shows how android system handles touches

whats touch event?

touch event starts when user touch the screen with 1/more fingers

what kind of information is gathered from touch event?

index/points of fingers, coordinate of touch & velocity (x & y)

how is event propagated?

dispatchTouchEvent()
event flow top down through views

dispatchTouchEvent()


event flow top down through views

how is Android Touch Handling?

user touch(motion event) is delivered to onTouchEvent() that provides detail of every user interaction

*ACTION_DOWN: first primary finger
*ACTION_POINTER_DOWN: second/more finger

user touch(motion event) is delivered to onTouchEvent() that provides detail of every user interaction




*ACTION_DOWN: first primary finger


*ACTION_POINTER_DOWN: second/more finger



whats a gesture?

its defined as beginning with ACTION_DOWN & ending with ACTION_UP




all actions between ACTION_DOWN & ACTION_UP

whats one finger gestures?

single touch

single touch

whats 2/more finger gestures?

multi touch

multi touch

custom gestures

how do you use gestures to enable the arrangement of view controls?

with drag/drop framework

challenges in working with gestures

a gesture can be made of multiple touch events/motions




different sequences of motion add up to different gestures where each sequence can trigger motion events that applications can react to

detecting user motion/gesture in UI view

it can be handled similar to click event




UI classes inheriting from view allow to set listeners that respond to basic gestures & listeners are defined bu suitable interfaces

approaches of gestures

whats MotionEvent object?

object created when the user touches the devices touchscreen

whats the sequence of MotionEvent?

- user touches the touchscreen


- user moves the finger on the screen


- user lifts up the finger

what kind of information does MotionEvent object contain?

- type of action captured


- pressure value


- x, y coordinates


- time of the event

how do you detect gesture?

gather data about touch event & interpret the data to find the pattern of any gestures of interest

what is drag & drop?

it allow users to move data from 1 view to another view i the current layout using graphical drag & drop gesture

whats included in drag & drop framework?

- drag event class


- drag listeners


- touch listeners


- helper methods & classes

whats the use of drag & drop?

drag an icon over another icon to obtain certain result




eg: color mix app

whats the steps of drag & drop operation?

how to setup drag event listener?

set the drag event listener object for a view with setOnDragListener() that have onDragEvent() callback method




contains an action type that tells the listener what is happening in the drag/drop process

the drag & drop process states

drag & drop process states : Drag Started

user makes a gesture to begin to drag, the app calls startDrag() to tell the system to start a drag




a drag shadow is provide

drag & drop process states : Drag Continuing

user continues the drag & the drag shadow intersects the bounding boxes of view objects

user continues the drag & the drag shadow intersects the bounding boxes of view objects

drag & drop process states : Dropped

user releases the drag shadow within the bounding box of a view that can accept the data




the listener is expected to return true if code for accepting the drop succeeds

drag & drop process states : Drag Ended

happens after the user releases the drag shadow where the event is sent to every registered listener

whats drag shadow?

during drag & drop operation, the system displays a shadow that the user drags indicating the data is being dragged

what size should the drag shadow be?

it should be small to improve performance

whats the steps of designing a drag & drop operation?

1. start a drag




2. respond to events during the drag




3. respond to drop event




4. end the drag & drop operation




5. responding to a drag end

designing a drag & drop operation : starting a drag

user starts drag with drag gesture (long press/touch)




- the data should be saved with ClipData


- define DragShadowBuilder to create a shadoe for dragging

how to allow a view to be dragged?

register OnTouchListener/LongClickListener on views




specify the data which is passed to the drop target using ClipDate

designing a drag & drop operation : responding to a drag start

during the drag operation, the system dispatches drag event to the drag event listener of the view objects in the current layout, & the listeners should react by calling getAction(0 to get station type

designing a drag & drop operation : handling events during the drag

during the drag, listeners that returned true in response to the ACTION_DRAG_STARTED drag event continue to receive drag events (location of the drag shadow & visibility of the listener's view)

designing a drag & drop operation : responding to a drop

the user releases the drag shadow on a view in the app where the system dispatches a drag event with ACTION_DROP action type

drop target

the views which can be drop targets get an instance of OnDragListener assigned

designing a drag & drop operation : responding to a drag end

immediately after the user releases the drag shadow, the system sends a drag event to all of the drag event listeners in the activity, with ab action type of ACTION_DRAG_ENDED

whats Google Maps API?

its a free component of the Google Play services library

what can we do with Google Maps?

how do we add Google Map into an app?

1. add permissions in manifest (internet, access_network_state, write external_storage, read_services from google)




2. register the app & get a personal API key with Google account




3. place the API key in the manifest file




4. check Google services APK (if (servicesOk))

how can we display a map?

1. create a new layout file using map fragment




2. use setContentView(R.layout.activity_map); in Java

how can we manipulate the map?

1. get a reference to the map object

2. use a method to check if the map has been initialized successfully

1. get a reference to the map object




2. use a method to check if the map has been initialized successfully

whats the initial state of the map?

its always centered in the same location at the intersection of Equator (double 0.0 latitude)& Prime Meridian (double 0.0 longitude)

how do we start a map from a customized location?

retrieve lat & lng of the locatin add inn XML/Java

change location in XML

can change map type with map:mapType (satellite, hybrid)

can change map type with map:mapType (satellite, hybrid)

change location in Java

add constants for the lat & lng 

add constants for the lat & lng

add zoom to location



whats Geocoding?

a process of converting address into geographic coordinate for adding place markers/position

what does Geocoder class do?

it wraps up all request & response functionality, returns everything back to as a Java object using getFromLocation & getFromLocationName

geolocate(View v)

how can you find the device's current location?

current location is found based on proximity to cell phone towers & wireless networks (coarse_location) & based on GPS (fine_location)

what permission do we need in manifest to get current location?

how do you get current location using non-code approach?

how do you get current location using in-code Java approach?

whats map markers?

it adds markers to a map

what can you do with map markers?

- adding & removing map markers




- customizing marker icon graphics




- handling marker events




- dragging & dropping markers

how do you add a marker?

how do you remove map markers?

map markers are removed when the activity is destroyed 

map markers are removed when the activity is destroyed

how do you customize marker icon?