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

INF422的TD2, 这节TD是要做一个多线程筛选质数的程序, 关于java的多线程, 以前用过但是不知道啥意思, 在这里总结下.

创建进程

为了实现多线程, 需要定义一个新的class, 有两种方法: 或者继承自Thread类, 或者实现Runnable接口(关键是重载run()方法).

继承自Thread类

  • 写法1: 定义一个继承自Thread的内部类--

    class [类名] extends Thread{
    方法1;
    方法2;
    
    public void run(){
    // …
    }
    属性1;
    属性2;
    
    }
    
  • 或者用下面种内联(inline)的写法, 不用给这个类起名字了(不过还要给这个实例取名字):

    private Thread [实例名] = new Thread () {
        public void run() {
        // ...
        }
    } ;
    

然后让进程开始, 就是: t.start(); 如果用 ...

这学期INF422, 第一节课就是android安装调试环境的搭建(居然要一节课?), 这里总结一下.

第一步: 下载bundle

下载ADT-Bundle 解压缩以后啥都有了, 包含一个eclipse...

第二步: 修改环境变量

linux下的环境变量放在.bashrc文件, 加入下面一行:

PATH=$PATH:<dir>/sdk/tools/:<dir>/sdk/platform-tools/:

其中<dir>是放置SDK的目录地址.

测试一下好不好使, 在终端中输入android, 看是否会弹出SDK manager

第三步: 新建一个virtual machine

可以用eclipse的AVDmanager做, 也可以用命令行做.

输入:

android list targets

找到想要的target(我们要4.1.2)的那个id(一个数字), 然后, 运行命令:

android create ...

S01E02: 开发环境搭建

  • 直接去 developer.android.com/sdk/ 下载bundle解压即可, 里面包含eclipse
  • 新建一个模拟器: 内部存储一般64MB足矣:

S01E03: android项目目录结构

第一个android程序

new-->android application

目录结构

  • com.example.helloworld这个包名一般为网址倒着写, android是按照包名来区分不同APP的
  • src/目录下存放java程序
  • gen/目录下存放系统自动生成的文件, R.java里给每一个控件或变量赋予一个id, 千万__不要手动修改R,.java内容__!!
  • assets/目录下和res/目录下都可以放各种外部文件(ex. 图片), 但是assets下的文件不会在R.java中生成id
  • res/layout/ 存放布局文件(xml格式)
  • AndroidManifest.xml用于统筹

S01E04: 技术结构

四层结构图

开发位于最上层application

基于组件的应用程序开发

搭积木

常见组件 ...