Skip to content

Instantly share code, notes, and snippets.

@Cee
Created July 7, 2015 11:54
Show Gist options
  • Save Cee/ea1e345a90cd46c88510 to your computer and use it in GitHub Desktop.
Save Cee/ea1e345a90cd46c88510 to your computer and use it in GitHub Desktop.
MCD

移动互联网开发

01 - Hello Android

过程

  • 配置开发环境和虚拟机 AVD
    • SDK & ADT(Android Developer Tools)
  • 开发,建立应用
    • Application Name
    • Package Name
    • Create Activity
    • Min SDK Version
  • 调试测试
  • 公开发布

代码

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TextView tv = new TextView(this);
    tv.setText("Hello Android");
    setContentView(tv);
}
// main.xml
<TextView android:android:text="@string/explanation" />

// strings.xml
<string name="explanation">blablabla</string>

03 - 移动互联网软件工程

移动互联网趋势

  • 用户的消费模式和商业模式
  • 涉及生活多方面

消费闭环

  • 支付
  • O2O
  • 广告

与软件工程关系

  • 定义:
    1. 将系统、规范、可度量的方法应用于软件的开发、运行和维护,即将工程应用于软件
    2. 对 1 中所述⽅法的研究
  • 移动互联网特点:
    1. 不确定性
    2. 要求高
    3. 环境复杂
  • 影响:
    1. 过程:快速迭代
    2. 技术:需求快速获取 交互 架构 测试
    3. 产品

04 - Application Fundamentals

Android Architecture

  1. Linux Kernel
    • 非 Linux 系统而是 Linux 内核
    • 无 glibc
    • 为何使用 Linux Kernel
      • 可靠性
      • 基础的平台
      • 和其他 Linux 平台一样
  2. Linux Kernel Drivers
    • Ashmen:內存分配器
    • Binder:C/S 模型,类似 IPC
    • Framebuffer:显示驱动
    • PM Solution:电源管理,wake locks

Hardware Abstraction Layer

硬件抽象层,使用 C/C++,定义了驱动的实现接口

  1. 原因
    • 并不是所有的逐渐都有标准的驱动接口
    • 内核驱动是 GPL 的
    • Android 有特殊的硬件需求

Libraries

  1. Native
    • Bionic Libc
      • 优势:BSD,小巧快速,但和 glibc 不兼容
    • Function Libraries
      • WebKit:网页支持
      • Media Framework:解码
      • SQLite:轻量级事务数据库
    • Native Servers
      • Surface Flinger:绘图
      • Audio Flinger:音效
    • Hardware Abstraction Libraries

Android Runtime

  1. Dalvik Virtual Machine(DVM)
    • .class/.jar → .dex
    • 适用于嵌入式环境
    • 核心库(Core Libraries)
    • DVM 和 JVM 区别
      • Google/Sun
      • Dalvik excutable/Java bytecode
      • 寄存器模型/栈模型

Application Framework

  • Activity Manager:进程生命周期
  • Content Provider:应用间分享数据
  • Resource Manager:管理非代码资源
  • Notification Manager:通知
  • Views System:绘制 UI

Applications

  • 电源管理的例子

Application Fundamentals

  1. 生成 .dex:.jar → .class → .dex(Use dx)
  2. Zygote
    • init 进程产生
    • 完成 DVM 初始化
    • 库加载
    • 新的应用开启时,fork 自身共享内存
  3. Application Components
    • Activities:界面 startActivity()
    • Services:后台 startService()
    • Broadcast receivers:通知,电量低 sendBroadcast()
    • Content providers:信息存储 query()
  4. AndroidManifest.xml
    • 申明所有 app 元素
    • 申明元素职责
    • Task
    • Screen Size/Input configurations/Device Features/Platform Version

05 - Activity & UI

Activity

  1. onCreate() Method
    • 必须需要,初始化元素
    • setContentView(what);
  2. onPause() Method
    • 离开 Activity 时调用
    • 保存持久化状态
  3. View Classes:XML/Code
  4. Intent filters:意图过滤器
  5. startActivity() & finishActivity()/finish()
  6. 代码
    // Start an activity in your application
    Intent intent = new Intent(this, SignInActivity.class);
    startActivity(intent);
  7. 生命周期
    • onCreate()
    • onStart()
    • onResume()
    • onPause()
    • onStop()
    • onDestroy()
  8. Bundle
    • 保存状态:onSaveInstanceState()
    • putString()

UI

  1. View & ViewGroup

    • 属性 properties
    • 焦点 focus:requestFocus();
    • 监听 listeners
    • 可见度 visibility:setVisibility(int);
  2. Layouts

    • setContentView(R.layout.main_layout);
    • Linear
    • Relative
    • Web View
    • Dynamic 时使用 Adapter:List View/Grid View
    • notifyDataSetChanged()
  3. Id

    • @ symbol:parse to id
    • + symbol:在 R.java 里生成
  4. 代码

    // onCreate()
    Button button = (Button)findViewById(R.id.my_button);
    // xml
    <Button android:id="@+id/my_button" />
    // Click Events Method 1
    private OnItemClickListener mMessageClickedHandler = new OnItemClickListener() {
    	public void onItemClick(AdapterView parent, View v, int position, long id) {
        	// Do something here
        }
    }
    
    listView.setOnItemClickListener(mMessageClickedHandler);
    // Click Events Method 2
    public class ExampleActivity extends Activity implements OnClickListener {
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
            Button btn = (Button)findViewById(R.id.my_button);
            btn.setOnClickListener(this);
        }
    
        public void onClick(View v) {
        	// Do something here
        }
    }
    // Click Events Method 3
    // xml
    <Button android:onClick="sendMessage" />
    // Activity.java
    public void sendMessage(View view) {
    	// Do something here
    }

06 - UI Design

  1. Tabs
  2. Categories
  3. Details
  4. Gestures
  5. Navigation
  6. Building Blocks
    • Tabs
    • Lists
    • Grid Lists
    • Scrolling
    • Spinners
    • Buttons
    • Text Fields
    • Seek Bars
    • Progress & Activity
    • Switches
    • Dialogs
    • Pickers
  7. Patterns

07 - Launch and Navigation

  1. Intent Object

    • Activity,Service,Receiver 都是由 Intent 唤起的
  2. Intent Resolution

    • Explicit/Implicit Intents
  3. Activity Lifecycle

  4. Action Bar

    • android.widget.ShareActionProvider
    • Navigation
  5. Fragment

    • Fragment 被放在 Activity 上,更加充分地利用平板的屏幕空间
    • ViewGroup
    • findFragmentByTag()/ById()
  6. Designing Effective Navigation

  7. 代码

    // Save State
    @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
    	savedInstanceState.putInt(STATE_SCORE, currentScore);
        super.onSaveInstanceState(savedInstanceState);
    }
    // Restore State
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	super.onCreate(savedInstanceState);
        if (savedInstanceState != null) {
        	currentScore = savedInstanceState.getInt(STATE_SCORE);
        } else {
        	// Do something here otherwise
        }
    }
    // Restore State using onRestoreInstanceState Method
    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
    	super.onRestoreInstanceState(savedInstanceState);
        currentScore = savedInstanceState.getInt(STATE_SCORE);
    }
    public class SampleFragment extends Fragment {
    	@Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        	return inflater.inflate(R.layout.sample_fragment, container, false);
        }
    }

08 - SDK

  1. SDK for Application Server and Application Platform
  2. SDK for Data Collection and Analysis
    • Umeng
    • App Annie
    • Flurry
    • 统计分析
    • 游戏统计分析
    • App 错误分析
    • 社会化⾏行为分析
  3. SDK for Development:推送
  4. Marketing

09 - Material Design

  • 个体、控件、⻚面
  • 关系、层级
  • 转移、切换

10 - Service and Broadcast Receiver

Service

  1. 服务
    • 在后台运行
    • 无 UI
    • getSystemService()
  2. 类型
    • Started:startService()
    • Bound:bindService()
  3. IntentService
  4. HanlderThread

Bound Service

```java
	// Bind
	protected void onStart() {
    	super.onStart();
        Intent intent = new Intent(this, LocalServices.class);
        bindService(intent, mConncetion, Context.BIND_AUTO_CREATE);
    }
	// Unbind
    protected void onStop() {
    	super.onStop();
        if (mBound) {
        	unbindServices(mConnection);
            mBound = false;
        }
    }
```

Broadcast Receiver

11 - 移动互联网应⽤需求分析

  1. 用户群特点
  2. 需求获取⽅法
  3. 需求的关注点
    • ⽤户特征
    • 行为特征
  4. 需求的角度
    • 战略:起步 发展 成熟 扩展
    • 产品
    • 功能
  5. 需求的组织
    • User Story:Scrum
    • Behavior Specification

12 - 移动互联网设计架构

  • 可用性
  • 扩展性
  • 低成本
  • 多快好省

13 - 移动互联网商业视⾓

  1. 前提条件
  2. 用户模式
  3. 盈利模式
  4. 创业
  5. 营销

14 - 移动互联网应用App体系结构

  1. MVC
  2. MVP:View Presenter Model(Database)

15 - Android 单元测试

Android Testing Framework

  1. Based on JUnit

16 - 移动互联网应⽤软件测试

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment