Andrews Component Study Notes

Andrews components

The components in the Android 1

  1. Two kinds of Hello World

Inheritance Activity, achieve OnCreate ()

Four major components:

  1. Activity content display, interaction with users
  2. Service long-running background
  3. BroadcastReceiver receive information, take the initiative to make a deal
  4. Management and sharing application data Content Provider

2 intent type:

Two kinds

  1. Explicit Intent: know the name of components, only one component can handle

  2. Implicit Intent: General statement operation performed in response to a plurality of applications running;

    ps: Start Service, an explicit Intent

3 intent matching rules

Implicit Intent matching rules in three dimensions

  1. action matching rules:
  2. Category matching rules
  3. data matching rules

Debugging intent tips: am Send intent commands to start the activity

语法:adb shell am start a、t、d、e、n

4 intent information transfer

Basic types:

Eight basic types of java + String reference type + CharSequence

Complex object in two ways:

  1. Serializable: serialize object into storable, only implements Serializable
  2. Parcelabe: between different components, better performance, inter-memory data transfer, need to customize packing and unpacking, preferred

5 Activity Lifecycle Management

Press the return key:

  1. Start the application onCreate-onStart-onResume
  2. Press return onPuse- Onstope- onDestrov
  3. Restart start onCreate-onStart-onResume

Press the Home key, Configuration change (screen rotation, change the font size, change the language, keyboard display hidden switch fonts, themes)

There will be restarted onDestroy, onCreat

6 ascend into the interface speed

Time Test Method: adb shell am start -W [packageName] / [PackageName.MainActivity]

Application launch key processes:

  1. 开始, Zygote创建进程--创建初始类Applicat--创建Acitivity--onCreate--配置主题信息--onStart--onResume--Measure/layout--显式

    优化的策略

    1. 耗时任务异步处理(onCreate(),onResume())
    2. 布局优化
      1. 减少布局层次去除冗余
      2. merge标签
      3. 自定义组件
      4. Viewstub
    3. 不可视图延迟加载
      1. 资源分开初始化
      2. addView
      3. 页面分开加载

7 service生命周期管理

后台长时间执行运行操作,不需要提供界面

启动方式

  1. bindService (组件与服务进行交互,发送请求)
  2. startService
    1. 服务启动后可以无限期运行
    2. 启动服务的组件已经被销毁了也不受影响

8 绑定Service

三种方式参考点

  1. 扩展Binder类(用用程序私有,客户端运行一个进程

    1. 服务端提供客户端可调用

    2. 扩展返回服务实例

  2. Messenger(不同进程间的通信,每次处理一个请求

    1. 客户端使用ibinder将message实例化,
    2. message对象向服务发命令
  3. AIDL文件(不同进程间, 服务每次处理多个请求

    1. Android接口定义语言
    2. 将对象解析为可识别的方式

9 接收器的注册

BroadcastReceiver用来响应系统范围内的广播事件的组件

事件----》AMS发送广播-----》APP(BroadcastReceiver)启动服务

两种注册方式:

  1. 静态注册 AndroidManifest.xml中声明
    1. Activity
    2. Service
    3. BroadcastReceiver
    4. ContentProvider
  2. 动态注册Context的子类中添加(BroadcastReceiver)

比较:静态注册常驻型,程序关闭亦可激活,动态注册非常驻,注册和注销需要成对出现。

10 广播的发送

无序广播:发送接受者内容相同,接受者不受到影响

有序广播:先到优先级高的接受者, 接受者可以停止广播,优先级可以获得经过处理的信息;

BroadcastReceiver 生命周期管理

从调用开始,到OnReceiver执行结束;

Android 教程

系统架构:

调试

通过单击工具栏上的按钮, Debug 'All Tests' 菜单命令,或者按 Shift+F9 快捷键,启动程序的调试模式

  • 快捷键 F8 单步执行程序。
  • 快捷键 F7 单步执行程序,遇到方法时进入。
  • 快捷键 Alt+F9 运行到光标处。

Activity声明周期,运行机制

‘参考书籍:《第一行代码》《Android 群英传》

Android Studio应用开发实战详解

Guess you like

Origin www.cnblogs.com/liguo-wang/p/11183286.html