Skip to content

Instantly share code, notes, and snippets.

@parahall
Created February 25, 2017 20:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save parahall/fba35b45f3d23261824c1e51f105deb3 to your computer and use it in GitHub Desktop.
Save parahall/fba35b45f3d23261824c1e51f105deb3 to your computer and use it in GitHub Desktop.
BackgroundService.java
public class BackgroundService extends Service {
@Override public int onStartCommand(Intent intent, int i, int i1) {
if (observer == null) {
observer = new OrdersObserver(new Handler());
getContext().getContentResolver()
.registerContentObserver(KolGeneContract.OrderEntry.CONTENT_URI, true, observer);
}
}
//...
@Override public void handleMessage(Message msg) {
super.handleMessage(msg);
Order order = (Order) msg.obj;
Intent intent = new Intent(context, SendOrderService.class);
intent.putExtra(SendOrderService.ORDER_ID, order.getLocalId());
context.startService(intent);
}
//...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment