Android

来源:互联网 发布:如何分析销售数据 编辑:程序博客网 时间:2024/06/12 11:49

1.屏幕适配

  1. 使用LinearLayout、RelativeLayout、FrameLayout
  2. 单位使用dp、dip、sp
  3. 代码中使用dip、sp等单位

    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics());

2.应用的Application

Appication:代表这个应用程序。对应AndroidManifest.xml的<application>节点,创建后需要在清单文件中进行配置。单例,可以保存全局变量进行数据传递。APK加载内存中后的第一个实例化对象。onCreate方法的执行优先于activity和service和receiver的实例创建(除了ContentProvider),可执行不耗时的初始化操作。service和activity可通过getApplication()获取到实例对象。

3.全局捕获异常

public class projectApplication extends Application {    //应用程序创建之前执行的第一个方法    //适合做应用程序的初始化操作    @Override    public void onCreate() {        //重写系统的异常处理器        super.onCreate();        Thread.currentThread().setUncaughtExceptionHandler(new MyExceptionHandler());    }    private class MyExceptionHandler implements UncaughtExceptionHandler{        //当发现了未捕获异常的时候调用的方法        @Override        public void uncaughtException(Thread thread, Throwable ex) {            System.out.println("发生了异常,但是被哥捕获了。。。");            //自杀的方法. 早死早超生            android.os.Process.killProcess(android.os.Process.myPid());        }    }}

4.Build类

提取设备硬件和版本信息内部类:  1、Build.VERSION 版本相关常量字符串  2、Build.VERSION_CODES 目前已知的版本代码的常量类静态属性  1、BOARD 主板:The name of the underlying board, like goldfish.  2、BOOTLOADER 系统启动程序版本号:The system bootloader version number.  3、BRAND 系统定制商:The consumer-visible brand with which the product/hardware will be associated, if any.  4、CPU\_ABI cpu指令集:The name of the instruction set (CPU type + ABI convention) of native code.  5、CPU\_ABI2 cpu指令集2:The name of the second instruction set (CPU type + ABI convention) of native code.  6、DEVICE 设备参数:The name of the industrial design.  7、DISPLAY 显示屏参数:A build ID string meant for displaying to the user  8、FINGERPRINT 唯一识别码:A string that uniquely identifies this build. Do not attempt to parse this value.  9、HARDWARE 硬件名称:The name of the hardware (from the kernel command line or /proc).  10、HOST  11、ID 修订版本列表:Either a changelist number, or a label like M4-rc20.  12、MANUFACTURER 硬件制造商:The manufacturer of the product/hardware.  13、MODEL 版本即最终用户可见的名称:The end-user-visible name for the end product.  14、PRODUCT 整个产品的名称:The name of the overall product.  15、RADIO 无线电固件版本:The radio firmware version number. 在API14后已过时。使用 getRadioVersion()代替。  16、SERIAL 硬件序列号:A hardware serial number, if available. Alphanumeric only, case-insensitive.  17、TAGS 描述build的标签,如未签名,debug等等。:Comma-separated tags describing the build, like unsigned,debug.

5.广告平台

国外:
StartAPP:http://www.startapp.com/

Google:http://www.google.cn/admob/

国内:

百度:http://app.baidu.com/index/appx

友盟,有米,万普等等

6.应用的混淆

  • project.properties里配置proguard.config=proguard-android.txt
  • 默认的混淆配置文件:sdk\tools\proguard\proguard-android.txt

注意事项:

  • release版本才会混淆
  • 四大组件,自定义View,还有一些其他保证完整性的代码不能混淆

混淆的优点:

  • 降低别人反编译代码的可读性
  • 压缩apk体积。

混淆的缺点:

  • 混淆配置错误导致debug版本没有而release才有的bug不易发现。
  • 运行时代码为混淆过的,降低了错误日志的可读性
原创粉丝点击