succlz123 / StarDriver-APT

Using Annotation Processor Tool to manage the initialization tasks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Star Driver

A library for managing the initialization tasks when an android application startup. It provides a simple way to control the order of tasks.

Version

Work Flow

The Tasks that need to be initialized in the application.

1

Automatically sort is based on before and after dependencies.

2

Usage

Build.gradle

implementation project(':stardriver-apt-lib')
implementation project(':stardriver-apt-annotation')
annotationProcessor project(':stardriver-apt-processor')

Init Task

public class AppInitLogger extends IStarDriver {

    @Override
    public void initialize(Context context, StarDriverResult result) {
        try {
          	// simulation initialization code
            Thread.sleep(23);
        } catch (InterruptedException e) {
            result.success = false;
            result.errorMessage = e.toString();
            return;
        }
        result.success = true;
    }
}

Setting task priorities

Option 1:

public class AppInitTaskHelper {

    // you can add the annotation on the field
    @StarDriverInit(name = "Application logger")
    public AppInitLogger logger;

    @StarDriverInit(name = "Info Report", after = {AppInitLogger.class})
    public AppInitTaskInfoReporting infoReport;
}

Option 2:

// you can also add the annotation on the class
@StarDriverInit(name = "Account Info")
public class AppInitAccountInfo extends IStarDriver {

    @Override
    public void initialize(Context context, StarDriverResult result) {
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            result.success = false;
            result.errorMessage = e.toString();
            return;
        }
        result.success = true;
    }
}

Application

public class MainApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
      	// The returned results contain the task name and time-taken.
        ArrayList<StarDriverStatisticsResult> results = StarDriverManager.inject(this);
    }
}

Plant UML

Copy the output of the build console into the StarDriverDigraph.puml file and install the Plant uml plug-in for Android Studio.

Then you can see the diagram like this.

1

About

Using Annotation Processor Tool to manage the initialization tasks.


Languages

Language:Java 100.0%