Git Product home page Git Product logo

asyncstarter's Introduction

asycstarter

Android异步初始化工具,更多内容请见博客:https://www.jianshu.com/p/ae0884e83c55

1.添加仓库

allprojects {
    repositories {
	...
	maven { url 'https://jitpack.io' }
    }
}
  1. 添加依赖
dependencies {
    implementation 'com.github.smartzheng:launcherstarter:1.0.2'
}

3.自定义Task

class InitTask : Task() {
    override fun needWait(): Boolean {//是否需要在阻塞在await(),在Application的onCreate方法之前执行完
        return true
    }

    override fun dependsOn(): MutableList<Class<out Task>> {//等待另一个Task执行完再执行此任务初始化
        return mutableListOf(InitTask1::class.java)
    }
    override fun runOnMainThread(): Boolean {//是否需要运行在主线程
        return true
    }
    override fun needRunAsSoon(): Boolean {//提高优先级,也可以指定优先级大小priority
        return true
    }
    override fun run() {
        //初始化
    }
}

4.在Application中

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        LauncherStarter.init(this)
        val starter = LauncherStarter.createInstance()

        starter.addTask(InitTask1())
            .addTask(InitTask2())
            .addTask(InitTask3())
            //addTask()...
        starter.start()
        starter.await()
        //LauncherStarter.createInstance()
        //            .run {
        //                addTask(InitTask1())
        //                    .addTask(InitTask2())
        //                    .addTask(InitTask3())
        //                    //addTask()...
        //                    .start()
        //                await()
        //            }
    }
}

asyncstarter's People

Contributors

smartzheng avatar

Watchers

James Cloos 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.