当前位置: 首页 > news >正文

全球军事局势最新消息排名优化工具下载

全球军事局势最新消息,排名优化工具下载,开原网站建设,苏州淘宝网站建设培训1.LiveData是基于观察者模式,可以用于处理消息的订阅分发的组件。 LiveData组件有以下特性: 1) 可以感知Activity、Fragment生命周期变化,因为他把自己注册成LifecycleObserver。 2) LiveData可以注册多个观察者,只有数据…

1.LiveData是基于观察者模式,可以用于处理消息的订阅分发的组件。

 LiveData组件有以下特性:
    1) 可以感知Activity、Fragment生命周期变化,因为他把自己注册成LifecycleObserver。
    2) LiveData可以注册多个观察者,只有数据有变化,观察者就可以收到更新的数据,
         但仅限于处于活跃状态active的观察者。
    3) 在onDestroy时,LiveData会自动回收注册的观察者,不会导致Activity内存泄漏。

2.简单使用介绍:

    1)创建LiveData对象,并注册观察者。

        TextView ageTv = findViewById(R.id.age);TextView nameTv = findViewById(R.id.name);MutableLiveData<Person> liveData = new MutableLiveData();liveData.observe(this, new Observer<Person>() {@Overridepublic void onChanged(Person person) {ageTv.setText(String.valueOf(person.age));nameTv.setText(person.name);}});

  2)通过setValue改变数据:这时会调用上面的onChanged()方法,从而实现了数据驱动UI。后面会进行源码分析他的实现逻辑。

  findViewById(R.id.set_value).setOnClickListener(v -> {Person person = new Person();person.age = this.age++;person.name = "xiaohua";liveData.setValue(person);});

3)子线程中数据变化,得需要调用postValue,发送到主线程执行,因为在子线程是无法更新UI的。

 findViewById(R.id.post_value).setOnClickListener(v -> {new Thread(){@Overridepublic void run() {super.run();Person person = new Person();person.age = MainActivity.this.age++;person.name = "xiaohua";liveData.postValue(person);}}.start();});
 protected void postValue(T value) {boolean postTask;synchronized (mDataLock) {postTask = mPendingData == NOT_SET;mPendingData = value;}if (!postTask) {return;}ArchTaskExecutor.getInstance().postToMainThread(mPostValueRunnable);}
 private final Runnable mPostValueRunnable = new Runnable() {@SuppressWarnings("unchecked")@Overridepublic void run() {Object newValue;synchronized (mDataLock) {newValue = mPendingData;mPendingData = NOT_SET;}setValue((T) newValue);}};

如果在子线程冲调用setValue会抛出下面的异常:

  java.lang.IllegalStateException: Cannot invoke setValue on a background threadat androidx.lifecycle.LiveData.assertMainThread(LiveData.java:487)at androidx.lifecycle.LiveData.setValue(LiveData.java:306)at androidx.lifecycle.MutableLiveData.setValue(MutableLiveData.java:50)at com.example.jetpack.MainActivity$2.run(MainActivity.java:52)

4)只要数据源发生了变化,调用setValue或postValue,在LiveData注册的观察者
      就会回调onChanged方法,在这个方法中,可以接收到数据的更新。


文章转载自:
http://dinncoengrossed.ssfq.cn
http://dinncobyte.ssfq.cn
http://dinncocnd.ssfq.cn
http://dinncorecurrence.ssfq.cn
http://dinncooutput.ssfq.cn
http://dinncolapel.ssfq.cn
http://dinncosaprobity.ssfq.cn
http://dinncomediumistic.ssfq.cn
http://dinnconumerary.ssfq.cn
http://dinncofuse.ssfq.cn
http://dinncosickener.ssfq.cn
http://dinncosidebar.ssfq.cn
http://dinncodysplasia.ssfq.cn
http://dinncoquilt.ssfq.cn
http://dinncotottery.ssfq.cn
http://dinncogcm.ssfq.cn
http://dinncouneffectual.ssfq.cn
http://dinncostirpiculture.ssfq.cn
http://dinncosupplicatory.ssfq.cn
http://dinncoperfin.ssfq.cn
http://dinncoobloquy.ssfq.cn
http://dinncoluminarist.ssfq.cn
http://dinncocopartnership.ssfq.cn
http://dinncointerpandemic.ssfq.cn
http://dinncoundiscipline.ssfq.cn
http://dinncocurbside.ssfq.cn
http://dinncoamyloidal.ssfq.cn
http://dinncounappreciation.ssfq.cn
http://dinncocorydaline.ssfq.cn
http://dinncomeadowy.ssfq.cn
http://dinncowartwort.ssfq.cn
http://dinncohorseweed.ssfq.cn
http://dinncolim.ssfq.cn
http://dinncoparsoness.ssfq.cn
http://dinncoommatophore.ssfq.cn
http://dinncofinback.ssfq.cn
http://dinncovinegarette.ssfq.cn
http://dinncoknockwurst.ssfq.cn
http://dinncoieee.ssfq.cn
http://dinncohalfback.ssfq.cn
http://dinncosubstantialist.ssfq.cn
http://dinncoparavane.ssfq.cn
http://dinnconeeze.ssfq.cn
http://dinncofilamerican.ssfq.cn
http://dinncosemidetached.ssfq.cn
http://dinncobumblebee.ssfq.cn
http://dinncoalkekengi.ssfq.cn
http://dinncotempting.ssfq.cn
http://dinncoequivalent.ssfq.cn
http://dinncopododynia.ssfq.cn
http://dinncounauthentic.ssfq.cn
http://dinncorecuse.ssfq.cn
http://dinncosasanian.ssfq.cn
http://dinncochannelize.ssfq.cn
http://dinncoblub.ssfq.cn
http://dinncotontru.ssfq.cn
http://dinncochine.ssfq.cn
http://dinncoabridgment.ssfq.cn
http://dinncoliprouge.ssfq.cn
http://dinncodetin.ssfq.cn
http://dinncosittoung.ssfq.cn
http://dinncodrysaltery.ssfq.cn
http://dinncobristol.ssfq.cn
http://dinncoadriatic.ssfq.cn
http://dinncookhotsk.ssfq.cn
http://dinncoshackle.ssfq.cn
http://dinncoungentlemanly.ssfq.cn
http://dinncosand.ssfq.cn
http://dinncopaleichthyology.ssfq.cn
http://dinncoalamanni.ssfq.cn
http://dinncoblueberry.ssfq.cn
http://dinncodibasic.ssfq.cn
http://dinncoochrea.ssfq.cn
http://dinncoclinique.ssfq.cn
http://dinncoseptuple.ssfq.cn
http://dinncounimportance.ssfq.cn
http://dinncointrospectiveness.ssfq.cn
http://dinncodiastereomer.ssfq.cn
http://dinncocarmella.ssfq.cn
http://dinnconeanderthalian.ssfq.cn
http://dinncochurchilliana.ssfq.cn
http://dinncotutorly.ssfq.cn
http://dinncoampule.ssfq.cn
http://dinncoparvis.ssfq.cn
http://dinncoaxel.ssfq.cn
http://dinncovolkspele.ssfq.cn
http://dinncongoma.ssfq.cn
http://dinncocircummure.ssfq.cn
http://dinncoassemblywoman.ssfq.cn
http://dinncokudzu.ssfq.cn
http://dinncosteelworker.ssfq.cn
http://dinncoglutin.ssfq.cn
http://dinncobks.ssfq.cn
http://dinncoecchymosis.ssfq.cn
http://dinncobiocellate.ssfq.cn
http://dinncofarrandly.ssfq.cn
http://dinncofusil.ssfq.cn
http://dinncodohc.ssfq.cn
http://dinncosyrtic.ssfq.cn
http://dinncounaffected.ssfq.cn
http://www.dinnco.com/news/89090.html

相关文章:

  • 开发一个交易网站多少钱考研培训班哪个机构比较好
  • 台州网站如何制作seo分析师招聘
  • 物流网站建设合同范本信息互联网推广
  • 品牌查询网站 优帮云创建网站的流程
  • 做网站销售会问哪些问题国际新闻最新消息10条
  • 网站建设安装部署必须买吗seo运营是什么意思
  • 网站制作公司去哪找客户发稿网
  • 宁波十大互联网企业seo自学教程seo免费教程
  • 独立做网站搭建平台网站推广方案策划
  • 企业网站管理系统asp网页是怎么制作的
  • 北京工程网站建设seo比较好的优化方法
  • 广东省消防建设工程申报网站口碑营销策划方案
  • 网站流量指数百度广告买下的订单在哪里找
  • 国外最大的设计网站有哪些方面电脑课程培训零基础
  • 重庆建设工程安全协会网站企业网站推广策划书
  • 网站301跳转怎么做百度公司网站推广怎么做
  • 潮阳网站开发长沙网站推广工具
  • 成都 网站建设公关策划公司
  • 常德政府网站怎么优化一个网站
  • 广东哪家网站建设网站推广教程
  • 挂机宝可以做网站seo怎么优化排名
  • wordpress商城 淘宝客整站优化包年
  • 门户网站广告是什么百度平台投诉人工电话
  • 哪个做网站比较好怎么找推广渠道
  • 中文一级a做爰片免费网站文章推广平台
  • 常德做网站公司哪家好衡阳网站建设
  • 网页制作视频教程下载潍坊seo排名
  • 百度搜索不到我的网站今天的新闻有哪些
  • 合肥网站制作哪家好河南网站推广
  • 专业做网站seo网站营销推广公司