[Blog Read] Android开发优化

来源:互联网 发布:mysql查看表空间占用 编辑:程序博客网 时间:2024/05/16 15:31

Android开发优化之——对界面UI的优化(1)     http://blog.csdn.net/arui319/article/details/8549849

    利用系统的ID,图片,字符串,style,颜色
    记得对include的内容设置margin、padding等内容,需要重新写layout_width和layout_height

Android开发优化之——对界面UI的优化(2)  http://blog.csdn.net/arui319/article/details/8554816

    使用include标签重用layout,也有style那样的问题

Android开发优化之——对界面UI的优化(3)  http://blog.csdn.net/arui319/article/details/8561757

    使用ViewStub延迟加载,这个暂时还没有实际用过。

Android开发优化之——从代码角度进行优化    http://blog.csdn.net/arui319/article/details/8537588  这篇不错

    避免使用静态的资源,尽量使用Application的Context,Resource等

private static Resources mResources; @Overrideprotected void onCreate(Bundle state) {    super.onCreate(state);    if (mResources == null) {        mResources = this.getResources();// 这里的resources引用了当前Activity,因此该Activity即使关闭了,也没法被回收        mResources = this.getApplication().getResources(); // 这里的resources不会引用Activity,因此不会影响Activity的回收    }}
    即使关闭资源

Cursor cursor = null;try{    cursor = mContext.getContentResolver().query(uri,null,null,null,null);    if (cursor != null) {        cursor.moveToFirst();        // 处理数据    }} catch (Exception e){    e.printStatckTrace();} finally {    if (cursor != null){        cursor.close();    }}
    listview的重用convertView和ViewHolder

    很多微调部分,这些没有深入来讲。

Android context(Application/Activity)与内存泄露   http://blog.csdn.net/ithomer/article/details/6891665

    专门讲context与内存泄露,Activity内对象的生命周期不要长于Activity。用Application的Context代替Activity的Context,避免内部静态类。

0 0
原创粉丝点击