项目作者: umang91

项目描述 :
Kotlin library to handle background processing
高级语言: Kotlin
项目地址: git://github.com/umang91/AsyncLib.git
创建时间: 2017-08-27T06:47:25Z
项目社区:https://github.com/umang91/AsyncLib

开源协议:

下载


MavenBadge

AsyncLibKotlin

Lightweight Kotlin library for performing tasks on background threads a.k.a. WorkerThreads.

This library has an advantage over the AsyncTask in android as one need not code extra for checking if
the Activity is still in foreground or the Fragment is still attached when the async execution
ends and the result needs to be updated on the UI.

Dis-advantage of using AsyncTask in your SDK/library is maximum number of concurrent tasks limit.
The OS restricts the maximum number of concurrent tasks to 128, as an SDK you might be
contributing to this limit which could ultimately result in some important tasks of app being
dropped off.

Installation

Add the below dependency in the app level build gradle.

  1. implementation("dev.assemblage:asynclib:$sdkVersion")

replace $sdkVersion with the latest SDK version.

Usage

Running on background thread and updating on ui thread without checks on the activity/fragment
state

  1. runAsync {
  2. //code to be run asynchronously
  3. onUIThread {
  4. //code to run on main thread
  5. }
  6. }

Running on background thread and updating on ui thread only if the activity has not finished

  1. runAsync {
  2. //code to be run asynchronously
  3. runOnActivityThread {
  4. //code to run on main thread
  5. }
  6. }

Running on background thread and updating on ui thread only if the fragment has not detached

  1. runAsync {
  2. //code to be run asynchronously
  3. runOnFragmentThread {
  4. //code to run on main thread
  5. }
  6. }