Skip to content
This repository has been archived by the owner on Jan 14, 2018. It is now read-only.

Best Practice for design to connect to multiple services #462

Open
eternalBlast opened this issue Oct 29, 2016 · 0 comments
Open

Best Practice for design to connect to multiple services #462

eternalBlast opened this issue Oct 29, 2016 · 0 comments

Comments

@eternalBlast
Copy link

eternalBlast commented Oct 29, 2016

Hi @stephanenicolas this is a superb library. I want to have two service. Can you give me a guide? FYI, my whole activities extend BaseActivity (or below class). If i implement an interface to this class i must call the method on my each sub class activities.

public abstract class BaseActivity extends AppCompatActivity {
  private static final String TAG = BaseActivity.class.getSimpleName();

  private SpiceManager spiceManager;

  public SpiceManager getSpiceManager() {
    if(PrefUtils.getPrefCity(getBaseContext()).equals("ABC"))
      spiceManager = new SpiceManager(MySecondService.class);
    else
      spiceManager = new SpiceManager(MyFirstService.class);
    return spiceManager;
  }

  @Override
  protected void onStart() {
    super.onStart();
    spiceManager.start(this);
  }

  @Override
  protected void onStop() {
    spiceManager.shouldStop();
    super.onStop();
  }

}

Before i change to the above class, here is my BaseActivity class

public abstract class BaseActivity extends AppCompatActivity {
  private static final String TAG = BaseActivity.class.getSimpleName();

  private SpiceManager spiceManager = new SpiceManager(MyFirstService.class);

  public SpiceManager getSpiceManager() {
    return spiceManager;
  }

  @Override
  protected void onStart() {
    super.onStart();
    spiceManager.start(this);
  }

  @Override
  protected void onStop() {
    spiceManager.shouldStop();
    super.onStop();
  }

}

Is there any way that give best practices design a spicemanager connect two service?
Or i must create two spice manager? Or is there any way i just check using if statement when getServerUrl() method is executed? Please help. Thanks in advanced.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant