Created
January 8, 2018 16:13
-
-
Save nazmulidris/7706b6fc1273520c6d42ad4d143aabe5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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