• 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/64

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;

64 Cards in this Set

  • Front
  • Back

what are the 5 persistent data storage options in android?

- SharedPreferences (key value pairs)


- Interal Storage (device memory)


- External Storage (shared external storage)


- SQLite Database (structured, private data)


- Network Connection (on web, with network server)

what are SharedPreferences? what's an example of data that'd be put in?

primitive data stored as key/value pairs




private to the app




e.g. username and password


key = username


value = "runnerDave"



what is internal storage? is it public or private to the app?

save files directly on the device's internal storage




private files to the app




if app is uninstalled, files are removed

what happens if app is uninstalled with data that's private?

all the data will go away

what's external storage? what's an example? is it public or private?

removable storage media


non-removable internal storage


readable by anyone -> public




e.g. SD card

in the SQLite database, what kind of data would you store? is it public or private?

complex and structured data


private to app




e.g. it's a table storing activity ID, type, distance, time, calories

what file is SharedPreferences stored in?

XML file (data/data//shared-prefs)

what is the kind of data that you store in SharedPreferences? and what are examples?

PRIMITIVE DATA: boolean long int float string




user info, location, when app was last updated, settings, if user is using app for first time

how to access preferences in code? 2 ways

getPreferences(int mode)


- just one shared preferences file



or getSharedPreferences(String name, int mode)


- means multiple preferences files saved, so you specify the name

what are the 4 steps to store data in SharedPreferences?

1. get references to SharedPreferences object


- getPreferences() or getSharedPreferences()




2. call the Editor edit()




3. use editor to add data with a key (e.g. putBoolean, putString)




4. commit editor changes commit()

what is SQLite?

language for managing data in relational databases

what class and method allows us to create the SQLite database? what about performing changes?

SQLiteOpenHelper




onCreate -> creates database


onUpgrade -> perform changes to database

how do you get the SQLite database object? it's a method

getWritableDatabase()

what are the 3 steps in creating SQLite database schema?

1. define schema


- database name, version, table names, column names




2. create database


- queries to create the database




3. execute queries


- insert, update, delete operations

when is onCreate() called? what does it do?

called when database is first created




creation of tables


initial data inside of table

when is onUpgrade() called? what does it do?

called whenever the database is updated



can drop, add tables, delete table, anything that updates the database structure/schema

each time you do a change in the database, WHAT do you have to change for it to update?

THE VERSION

what is the SQLiteDatabase class?

An object representing the database that was created

what does public void execSQL(String sql) do? what's an example?

executes a single SQL statement




e.g. db.execSQL(CREATE_TABLE)

what is the condition for the database to get created? what's the line of code?

only when there is an attempt to access it for the first time




call the method getWritableDatabase()

how to insert new row in database? what query is it and how do you do it

insert query




1. create an object of class ContentValues




2. contentValues.put(Constants.NAME, name);


(key, value)




3. long id = db.insert(Constants.TABLE_NAME, null, contentValues);

what does nullColumnHack do?

lets you insert a row that's empty

what 3 classes should you separate your database code into?

MyDatabase class


- contains SQLite Database instance and helper




MyHelper class


- extends SQLiteOpenHelper class and contains onCreate() and onUpgrade()




Constants class


- holds String constants like table names

how to read data from database? what's the method? what does that method return?

query() - returns a Cursor object with the results of the query

what does SimpleCursorAdapter do?

for ListView: maps columns from a cursor to TextViews or imageViews defined in an XML file

diff between process and thread in terms of memory space




what can one process be associated with?

process


- run in their OWN memory space




thread


- share same memory space




one process can be associated with several threads

what is a process?

executing instance of an application

what is the default 3 steps of processes and threads in android starts?

1. application component starts FIRST TIME


- no other component is running




2. android starts NEW PROCESS in a single thread of execution




3. another component of the app starts, and it runs in same process and same thread

before terminating a process, what does android do? what will be terminated last?

assess its importance/priority in reference to the user




the processes with which the user is interacting at that moment have higher priority

what are foreground processes?

processes that have current user interaction

what is the ranking of process termination?

1. foreground


2. visible processes


3. service process


4. background process


5. empty process

what are examples of activity, service, and braodcast receiver in its highest priority/foreground?

activity


- when onResume()




service


- when the service is BOUND to the current activity


- when there's user interaction




broadcast receiver


- while executing onReceive() method

what does visible processes mean? how do we define it? give an example in terms of activity and service

when the activity is onPause(), the user can still SEE it




or service is bound to a visible activity

what is a background process defined as? how to determine last to be destroyed?

no user interaction at all




the app most recently seen by the user is the last one to be destroyed



what does empty process mean? why is it still running?

no active component running




still alive for caching purposes

what is a service process? how is it ranked?

process running a service




ranked higher than a process that does not have a service

if you have a long-running operation, what should you use rather than an async thread? and why?

use a SERVICE (it can only go low as 3)




if you use an async thread, it's still in the same process so it might become background (and can get ranked 4)

what is a long-running operation? give some examples

everything that exceeds a few seconds




everything that goes out of the application sandbox




- working with files


- network access


- database access


- complex calculations

why don't you want to put long-running operations in the main thread?

blocks the UI so main thread will be busy processing long-running operations so other things in the queue will be delayed

what do you need to keep in the main thread?

UI

3 ways to enable responsiveness

AsyncTask helper class - recommended


- complete tasks asynchronously and communicate back to the main UI thread




Java Thread class




Loader class


- facilitate the loading of data for use in activity or fragment while still starting up quickly

async task is good for tasks lasting how long?

100ms to a few seconds

2 reasons to use AsyncTask as opposed to java approaches?

1. easier to implement in comparison to thread and handler




2. automates:


- creation termination of background thread


- managing of message queues


- updating on progress

what are the 2 steps of implementing AsyncTask? what can overriding its methods do? 3 things

1. create subclass of AsyncTask




2. override one or more AsyncTask methods to:


- do work inside bg thread


- handle UI updates in main thread


- when needed, create instance and call execute() to have it begin doing its work

what are the methods in order of the steps for AsyncTask? what do these methods do?

execute()


onPreExecute()


- callback


- maybe make a progress bar




------ task running


doInBackground()


- where the actual work happens (e.g. network calls)


- called in bg thread


publishProgress()


- we can send value about the progress


- called in bg thread


onProgressUpdate()


- triggered from publishProgress


- update UI elements




----- task finished


onPostExecute()


- called on main thread after result is returned


- clean up work e.g. we don't need progress bar so hide it

what are the 3 parameters you can send with AsyncTask methods?

Param




Progress




Result

what are the callback methods in AsyncThread? what do you have to call?

onPreExecute()


doInBackground()


onProgressUpdate()


onPostExecute()




execute() and publishProgress()

what are the 2 types of services?

started


bound

what is a started service? what's it started by? is it single operation? what does it return? who stops it?

runs in bg even if the component that started it is destroyed!!




started by startService()


single operation


doesn't return result to caller




you can stop itself or have the activity stopService() it

what is a bound service? when does it run? what do you call to use it?

bindService()




there's an app bound to it




runs only as long as a component is bound to it

can you have a started service to run indefinitely that allows binding?

yes

where does the service run? (e.g. which thread and process)

runs in MAIN THREAD and doesn't run in a separate process

what is the service lifecycle (4 methods)

onCreate()


onStartCommand()


onBind() -> if service allows binding


onDestroy()

what is the started service lifecycle? what happens if the service is stopped?

1. startService() started by another component


2. onCreate()


3. onStartCommand()


4. stopSelf() or stopService()


5. onDestroy()




when service stopped, system DESTROYS it

what is the bound service lifecycle? how does it get stopped/destroyed?

1. bindService() - another component (client) calls


2. onCreate()


3. onStartCommand()


4. unbindService() - client can close connection


5. onDestroy()




multiple clients can bind to same service when all of the unbind, system destroys the service

what does it mean that the service has a lifecycle independent of the component that started it?

it means if the component is destroyed, the service isn't destroyed

what is the base class for all services and what does it do?

Service class




creates new thread to perform the service's intensive work

what is IntentService class?

subclass of service class




worker thread to handle all starter requests

should you create a new thread inside your service?

depends - if it's a large bg job then yes (e.g. playing music from the web)

what does cursor object give us access to, and what does it allow?

the results returned from a database query




allows navigation through the result set

what is the main method of the intent service class? what does it do?

onHandleIntent()




receives intent for each start request

what is the param parameter in AsyncTask?

type of parameter sent to task for execution

what is the progress parameter in AsyncTask?

type of info used to indicate progress

what is the result parameter in AsyncTask?

type of result received from bg task