diff --git a/docs/HeadlessJSAndroid.md b/docs/HeadlessJSAndroid.md index 763f58c28..584e6d40c 100644 --- a/docs/HeadlessJSAndroid.md +++ b/docs/HeadlessJSAndroid.md @@ -50,17 +50,29 @@ public class MyTaskService extends HeadlessJsTaskService { } ``` -Now, whenever you [start your service][0], e.g. as a periodic task or in response to some system event / broadcast, JS will spin up, run your task, then spin down. - -Remember to add the service to your `AndroidManifest` file: +Then add the service to your `AndroidManifest.xml` file: ``` ``` +Now, whenever you [start your service][0], e.g. as a periodic task or in response to some system event / broadcast, JS will spin up, run your task, then spin down. + +Example: + +```java +Intent service = new Intent(getApplicationContext(), MyTaskService.class); +Bundle bundle = new Bundle(); + +bundle.putString("foo", "bar"); +service.putExtras(bundle); + +getApplicationContext().startService(service); +``` + ## Caveats -* By default, your app will crash if you try to run a task while the app is in the foreground. This is to prevent developers from shooting themselves in the foot by doing a lot of work in a task and slowing the UI. There is a way around this. +* By default, your app will crash if you try to run a task while the app is in the foreground. This is to prevent developers from shooting themselves in the foot by doing a lot of work in a task and slowing the UI. You can pass a fourth `boolean` argument to control this behaviour. * If you start your service from a `BroadcastReceiver`, make sure to call `HeadlessJsTaskService.acquireWakelockNow()` before returning from `onReceive()`. [0]: https://developer.android.com/reference/android/content/Context.html#startService(android.content.Intent)