Skip to content

Service Extras Builder

Roman Tcaregorodtcev edited this page Apr 2, 2018 · 1 revision

Simple way to create and put data to service.

  • @OmegaService - annotation for services.
  • @OmegaExtraModel - annotation for classes, which will be putted to bundle.
  • @OmegaExtra - annotation for fields, which will be putted to bundle.

@OmegaExtraModel and @OmegaExtra support prefix for generated method name.
If you wan't annotate your class with @OmegaExtra - this class should be implements Serializable

Usage

First step - annotate your service with @OmegaService

Second step - annotate fields with @OmegaExtraModel or @OmegaExtra

@OmegaService
public class TestService extends IntentService {

    private static final String TAG = TestService.class.getSimpleName();

    @OmegaExtra
    String value;

    @OmegaExtraModel(prefix = "model")
    Model model = new Model();

    public TestService() {
        super(TAG);
    }

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {
        AppOmegaIntentBuilder.inject(this, intent);
        Log.d(TAG, value);
        Log.d(TAG, model.getUrl());
    }
}

Third step - don't forget write AppOmegaIntentBuilder.inject(this) in onHandleIntent method.

Model class

public class Model implements Serializable {
    @OmegaExtra("Var2")
    String url;

    public String getUrl() {
        return url;
    }
}

Fourth step - fill out your data.

AppOmegaIntentBuilder.from(this)
                .appServices()
                .testService()
                .value("Great library")
                .modelVar2("Omega-R")
                .startService();