Giter Site home page Giter Site logo

ilivedata's Introduction

ILiveData

对LiveData进行封装。

引入依赖:

How to To get a Git project into your build:

步骤1. Add the JitPack repository to your build file

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

步骤2. 加入ILiveData

dependencies {
	implementation 'com.github.ming123aaa:ILiveData:1.6'
}

步骤3.加入lifecycle的依赖:

         implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'

步骤4.代码混淆:

           -keep class com.Ohuang.ilivedata.*{*;}
           -keep class androidx.lifecycle.* { *; }
           -keep class androidx.arch.core.internal.*{*;}'

简单使用:

MyLiveData的使用

发送数据:

  // with(一个String类型的key,需要传递对象的类型)   setValue(需要传的对象)
 
  MyLiveData.getInstance().with("aa",String.class).setValue(string);
 
// 如果在子线程请使用postValue

  MyLiveData.getInstance().with("aa",String.class).postValue(string);

接收数据:

 //with(,)这两个参数与上面一致.  observe(类型为LifecycleOwner在Activity或Fragment里面直接this就行,观察者)
  MyLiveData.getInstance().with("aa",Person.class).observe(this, new Observer<Person>() {
          @Override
          public void onChanged(Person person) {
          //...执行接收数据后的操作

          }
      });

LiveDataBus的使用与MyLiveData的使用相同 两者的区别,LiveDataBus没有粘性事件,MyLiveData自带粘性事件。

LiveDataBus.get().with("1",String.class).setValue("123");

ilivedata's People

Contributors

ming123aaa avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.