Save settings and configurations.

Data Persistance

5 different ways of data persistance:

  • onSavedInstanceState(): store state of views in k-v pairs (Bundles), used when screen rotates / app killed by system, temperary.
  • SharedPreferences: save k-v pairs to a file, can save primitive types.
  • SQLite database: complicated data types
  • Internal / External Storage: save ...

Android kills background apps !!

onCreate()CreatedonStart()Visible(can be seen on screen) → onResume()Active(get focus, can interact with)

ActiveonPause()Paused(lose focus — same thing as Visible?) → onStop()Stopped(disappeared) → onDestroy()Destroyed(lifecycle ends)

when rotate screen, the function calling is:

onPause --> onStop --> onDestroy --> onCreate --> onStart --> onResume

note ...

Recycler View, Adaper, ViewHolder

rather than creating list items as we scroll, keep them in a queue (recycling bin) → when scrolling, the list items are recycled and re-bind to new content. RecyclerView is better version of ListView.

Adaper: bind data from data source, and provide the RecyclerView with new views ...

So far: single screen with a single activity.

start activity from another activity: use Intents.

Explicit intent: start a new activity

toy app: type some text, press button, and a new activity will appear with the typed words.

create activity in android studio: new → activity

call startActivity with an ...

1 create project sunshine

Created 星期一 06 二月 2017

minSDK vs targetSDK

The minSDK is the lowest SDK level that your app can run on. You can choose what level of devices to support.

By comparison, the targetSDK is NOT a high pass filter -- it’s used only to declare ...

this week: programming-in-the-large using the module system of OCaml.

1. STRUCTURING SOFTWARE WITH MODULES

in large project: mangage high number of definitions → abstractions built on top of other abstractions.

  • layers of abstractions: hide information
  • divide program into components
  • identifiers organised to avoid naming conflicts

module as namespace

dot-notation: access module ...

1. IMPERATIVE FEATURES IN OCAML

functional language:

  • immutable data structure
  • identifiers instead of variables
  • pure functions

but imperative features are useful:

  • exceptions to alter control flow
  • ops to consume input and output
  • mutable data structures
  • for and while loop for iterations

2. GETTING AND HANDLING YOUR EXCEPTIONS

  • exceptions in ocaml ...

1. FUNCTIONAL EXPRESSIONS

syntax for functional expr: function some_identifier -> some_expr
the type of the functional expr is t1 -> t2 where t1 is the type of some_identifier, t2 is type of some_expr

ex.

function x -> x + 1;;  
(function x -> 2*x) 5;; (*annonymous function*)   

the previous way of defining function:

let ...

Last week, we only defined flat data structures which are nice to aggregate values but quite limited when you try to structure values.

This week: algebraic datatypes.

1. TAGGED VALUES

⇒ change the return type to a type query_result, which can be either of these:

  • an error
  • a new database (in ...