一个轻量级的处理耗时任务的Android库

Create your peanut.

val peanut = object : Peanut<String>() {
            override fun call() {
                var count = 0
                for (i in 0 until 100000) {
                    count += count
                }
                onSuccess(count.toString())
            }
}

and Schedule it

peanut.runOn(Schedulers.io())
                .receiveOn(Schedulers.main())
                .run(object : Peanut.Subscriber<String> {

                    override fun onComplete(data: String) {
                        count.text = data
                    }

                    override fun onError(e: Error) {
                        e.printStackTrace()
                    }
})

Dependency

Add it in your root build.gradle at the end of repositories:

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

Add the dependency

dependencies {
	 implementation 'com.github.savepopulation:peanut:v1.0.0'
}

猜你喜欢

转载自blog.csdn.net/mr___xu/article/details/80817827