So I have two Services in my app FooService and BarService. What would be the most efficient way to communicate between these services? More specifically, how is communication via sending intents with actions using startForegrounService different from sending broadcasts using local broadcast manager?
Using onStartCommand
FooService.class
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
final int i = super.onStartCommand(intent, flags, startId);
String intentAction = null;
if(intent!=null)
intentAction = intent.getAction();
if(intentAction ==null)
return i;
switch (intentAction) {
case "Message A":
// do something with Message A
break;
case "Message B":
// do something with Message B
default:
return i;
}
return i;
}
BarService.class
Intent myIntent = new Intent(this, FooService.class).setAction("Message A");
startService(myIntent
);