美文网首页
各种杂记想到就记

各种杂记想到就记

作者: 在一颗大大大榕树下 | 来源:发表于2019-03-18 15:31 被阅读0次

1. SparseArray

  • 是Android特有的API
  • 比HashMap节省内存
  • 正序插入效率高于HashMap,倒序反之。
  • 底层插入时都要使用二分查找,寻找当前插入索引是否在范围内。

2. 通过Object获取数组对象,如果对象不是数组类型,则会返回空值

Class<?> class = arrLhs.getClass().getComponentType();

3. putIfAbsent和put的区别

putIfAbsent在放入数据时,如果存在重复的key,那么putIfAbsent不会放入值。
如果传入key对应的value已经存在,就返回存在的value,不进行替换。如果不存在,就添加key和value,返回null

4. 当一个变量定义为 volatile 之后,将具备两种特性:

1.保证此变量对所有的线程的可见性,这里的“可见性”,如本文开头所述,当一个线程修改了这个变量的值,volatile 保证了新值能立即同步到主内存,以及每次使用前立即从主内存刷新。但普通变量做不到这点,普通变量的值在线程间传递均需要通过主内存(详见:Java内存模型)来完成。

2.禁止指令重排序优化。有volatile修饰的变量,赋值后多执行了一个“load addl $0x0, (%esp)”操作,这个操作相当于一个内存屏障(指令重排序时不能把后面的指令重排序到内存屏障之前的位置),只有一个CPU访问内存时,并不需要内存屏障;(什么是指令重排序:是指CPU采用了允许将多条指令不按程序规定的顺序分开发送给各相应电路单元处理)。

5. java.lang.Class.isPrimitive()

此方法主要用来判断Class是否为原始类型(boolean、char、byte、short、int、long、float、double)。

public static void main(String[] args){

    Class stringClass=String.class;
    System.out.println("String is primitive type:"+stringClass.isPrimitive());

    Class booleanClass=Boolean.class;
    System.out.println("Boolean is primitive type:"+booleanClass.isPrimitive());

    Class booleanType=boolean.class;
    System.out.println("boolean is primitive type:"+booleanType.isPrimitive());

    Class byteType=byte.class;
    System.out.println("byte is primitive type:"+byteType.isPrimitive());

    Class charType=char.class;
    System.out.println("char is primitive type:"+charType.isPrimitive());

    Class shortType=short.class;
    System.out.println("short is primitive type:"+shortType.isPrimitive());

    Class intType=int.class;
    System.out.println("int is primitive type:"+intType.isPrimitive());

    Class longType=long.class;
    System.out.println("long is primitive type:"+longType.isPrimitive());

    Class floatType=float.class;
    System.out.println("float is primitive type:"+floatType.isPrimitive());

    Class doubleType=double.class;
    System.out.println("double is primitive type:"+doubleType.isPrimitive());
}

输出结果:

String is primitive type:false
Boolean is primitive type:false
boolean is primitive type:true
byte is primitive type:true
char is primitive type:true
short is primitive type:true
int is primitive type:true
long is primitive type:true
float is primitive type:true
double is primitive type:true

6. NestedScrollView

  • [NestedScrollView] 即 支持嵌套滑动的 [ScrollView]。
  • [NestedScrollView]与 [ScrollView]一样,内部只能容纳一个子控件。

7. Log.isLoggable()的日志级别设定

Log.isLoggable(String tag, int level),检查当前的tag是否在指定的log级别,下方代码就修改了Log等级和内容。

try{
  ...
}catch (e: ClassNotFoundException){
            if (Log.isLoggable(TAG, Log.WARN)) {
                Log.e(
                    TAG, "ClassNotFound"
                )
            }
}

8. 判断当前线程的方法
判断当前线程的Looper是否是主线程的Looper

//判断当前是否后台线程
 public static void assertBackgroundThread() {
    if (!isOnBackgroundThread()) {
      throw new IllegalArgumentException("You must call this method on a background thread");
    }
  }
//判断当前是否主线程
  public static void assertMainThread() {
    if (!isOnMainThread()) {
      throw new IllegalArgumentException("You must call this method on the main thread");
    }
  }

/**
   * Returns {@code true} if called on the main thread, {@code false} otherwise.
   */
  public static boolean isOnMainThread() {
    return Looper.myLooper() == Looper.getMainLooper();
  }

  /**
   * Returns {@code true} if called on a background thread, {@code false} otherwise.
   */
  public static boolean isOnBackgroundThread() {
    return !isOnMainThread();
  }

9. 根据内容生成图片

image.png
  • view转bitmap
  • bitmap直接画


    image.png

10.直播 七牛 云

11. Android吹比名词
UI:泛指用户的操作界面,包含移动APP,网页,智能穿戴设备等。
UE:用户使用产品时的纯主观感受。
UX:人与系统交互时的感觉。

12. Android7.0新特性
shortcut APPICON长按出现桌面菜单栏

相关文章

  • 各种杂记想到就记

    1. SparseArray 是Android特有的API比HashMap节省内存正序插入效率高于HashMap,...

  • 散·杂·笔

    本人的记录分为散记、杂记、笔记。 散记,不分类,随心随记。杂记,分类,记录若干范畴的心得,比如物理。笔记,分类,记...

  • 文学课堂:文体基本常识

    杂记的主要分类 杂记主要包括以下两大类:一类是描写山川、景物和人物的,例如《小石潭记》、《登泰山记》;一类是以记事...

  • 多才多艺

    从2005年寒假,第一次看到你的博客。就见识了你的各种文字。散文、小说、日记、杂记,甚至笑话等。各种文字都好喜欢。...

  • 杂事啊

    最近迷上了“杂记”,头脑像浆糊一样择不清理还乱,想个事都觉得累,怎么办,生活中的瞬间记一记,不然以后肯定会忘的,就...

  • 《西京杂记》评

    余近读《西京杂记》,其叙事文风为素来所喜,故妄评之。 西京者,汉之都城长安也。杂记者,但有可志之事物人情,辄记之。...

  • 《西京杂记》小考

    余近读《西京杂记》,其叙事文风为素来所喜,故妄评之。 西京者,汉之都城长安也。杂记者,但有可志之事物人情,辄记之。...

  • 书《百牙塔记》文后

    按姚鼐《古文辞类篹》所列十三种文种分类,拙作《百牙塔记》无疑属于杂记类。 众者耳熟能详之杂记大家,一定非柳宗元莫属...

  • Excel函数公式太复杂记不住?只要记住这4个很常用的公式就足够

    Excel函数公式太复杂记不住?其实,不用全部都去记的,只要记住这4个最常用的公式就足够了~(公式可直接套用) 1...

  • 宝妈备战考研第32天

    酱紫哇的学习杂记 【 2019.12.2 】 【 考研倒计时:389天 】 【 备战考研:D32 】 ❣️今天只记...

网友评论

      本文标题:各种杂记想到就记

      本文链接:https://www.haomeiwen.com/subject/cbgarqtx.html