Started services by default does not create its own thread or run in a separate process, it runs on the main thread of the application. There are two ways to make a service concurrent.
- by adding in AndroidManifest.xml as service property android:process=”ProcessNamE” This way a different processed is used, and it is not recommended because it can use a lot of system resources.
- by using IntentService instead of Service that automates and simplifies the programming of concurrent started services. IntentService extends the started service and it is very easy to use. You just need to override one hook method. Basically it handles one background thread at a time.
You can start an IntentService with startService(Intent) and you can pass information/data with the intent via setData() or by putting extras.
Intent intent = new Intent(this, MyService.class); startService(intent);
To implement an Intent Service create a class that extends IntentService and override and implement onHandleIntent()
- Easy to implement, just override one hook method
- Not using a lot of resources
- No need to handle runtime configuration changes
- Only one intent can be processed at a time
- Can interact with the user in limited ways
- Android – Notifications
- Content Provider – Part 3 – insert, delete, update, getType
- Content Provider – Part 2 – create and query