Adroid开发错题集

  • 错误:android - Binary XML file line #2: Error inflating class
  • 原因:是bitmap图片过大,或xml书写有误(如selector定义出错)

Dagger2中如果@Inject注解的构造函数非public将不会被纳入Dagger控制的类


  • Observable.concat(A, B)当A为hot observable时会忽略后续所有的observable,应注意。文档原文如下:

Concat waits to subscribe to each additional Observable that you pass to it until the previous Observable completes. Note that because of this, if you try to concatenate a “hot” Observable, that is, one that begins emitting items immediately and before it is subscribed to, Concat will not see, and therefore will not emit, any items that Observable emits before all previous Observables complete and Concat subscribes to the “hot” Observable.


  • 解决办法:Observable.concat(hotObservable.first(), coldObservable).subscribe(); 其中,first()方法能够时hot observable转变为cold observable,一个single。

  • realm中设置primary key要小心,比如记录不同周次的object, 该object中的成员最好也按照(唯一名称+周次).hashcode()作为唯一id的primary key; 同时数据库版本升级要migration。


  • 当rxjava中需要skip流中发生的error时可使用onErrorResumeNext(Observable.empty()),防止concat(dataFromStore, dataFromServer)时流中出错导致中断。

  • The task can be executed only once (an exception will be thrown if a second execution is attempted.)
  • AsyncTask只能execute()一次,cancel()不能restart。

  • List用iterator可以放心remove()

  • 要使得ListView,RecyclerView有ScrollView的效果。
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
    MeasureSpec.AT_MOST);
    super.onMeasure(widthMeasureSpec, expandSpec);
}

  • Throwable是Error和Exception及其子类的超类,用Throwable作为异常或错误抛出。因此用instanceof分辨自定义异常或错误时要调用Throwable.getCause()。

你可能感兴趣的:(Adroid开发错题集)