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 ...

2016年的最后几小时, 随便写写关于Scala和OCaml的一些入门体验好了.

今年对FP语言特别感兴趣, 上了两门Scala的公开课(here and here)和一门OCaml的公开课(here), 在博客中写了一系列的笔记, 课后作业也都认真做完了. 斗胆说这两门语言都算入门了吧... 这里就随便写一下使用这两门语言的感受, 想到哪里写到哪里...

FP语言和之前接触的语言确实不大一样, 比如之前我都有种错觉, 学什么语言只要知道循环/条件/基本类型运算怎么写, 就差不多可以上手了...... 然后遇到了FP, 发现循环语句其实是不必要的... 记得看到过一篇文章, 类比学FP就好像开了很多种车的老司机突然开始学开宇宙飞船, 肯定各种WTF不适应了~

以前谈到FP我只能联想到一些Python里的FP特性: lambda表达式, 高阶函数之类的, 顶多还想到个闭包... 不过Python里面的FP特性和Scala/OCaml里的比起来还是差了不少: i.e. 现在非常希望Python里可以支持pattern matching...

Scala

Scala算是比较亲民的FP语言了(和Java有点像...), 也是我最早接触的FP语言. EPFL的那两门公开课质量很棒, 毕竟是Scala的作者亲自来上的...

  • immutable types: 习惯了就好, 就像java里所有东西都是final的, 要修改什么东西的时候改成新建一个, immutable数据的优点就是并行方便啊...
  • 一切皆为表达式, specifically, if ...

前一段时间写了不少Python的爬虫程序, 为此还看了极客学院上的一些教程, 现在来简单总结一下. 主要介绍用requests + lxml的方式, scrapy的话之前写过一篇介绍性的文章, 这里就不重复了. 而且感觉一般简单的爬虫项目, 一个Python文件就基本可以搞定, 没必要用scrapy建立一个工程文件夹搞那么正式...

安装需要的库(python2):

pip install requests, lxml

然后在Python程序最开始导入:

import requests  
from lxml import etree

requests基础用法

抓取html内容

用requests获取目标网址的html代码非常简单, 只需要用requests.get方法, 传入网址URL即可.

举个例子, 想要抓取维基语录的HTML内容, 代码很简单:

url = 'https://zh.wikiquote.org/zh-cn/阿爾伯特·愛因斯坦'  
r ...

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 ...