Skip to content

Instantly share code, notes, and snippets.

@nazmulidris
Created January 8, 2018 16:13
Show Gist options
  • Select an option

  • Save nazmulidris/7706b6fc1273520c6d42ad4d143aabe5 to your computer and use it in GitHub Desktop.

Select an option

Save nazmulidris/7706b6fc1273520c6d42ad4d143aabe5 to your computer and use it in GitHub Desktop.
public class MyService extends Service{
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
boolean containsCommand = MyIntentBuilder
.containsCommand(intent);
d(TAG,
String.format(
"Service in [%s] state. cmdId: [%d]. startId: [%d]",
mServiceIsStarted ? "STARTED" : "NOT STARTED",
containsCommand ?
MyIntentBuilder.getCommand(intent) : "N/A",
startId));
mServiceIsStarted = true;
routeIntentToCommand(intent);
return START_NOT_STICKY;
}
private void routeIntentToCommand(Intent intent) {
if (intent != null) {
// process command
if (containsCommand(intent)) {
processCommand(MyIntentBuilder.getCommand(intent));
}
// process message
if (MyIntentBuilder.containsMessage(intent)) {
processMessage(MyIntentBuilder.getMessage(intent));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment