Android – Services and concurrency PART 3

You can also read Part 1 and Part 2.

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.

  1. 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.
  2. 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);

To implement an Intent Service create a class that extends IntentService and override and implement onHandleIntent()

how to implement and intentservice, <span>Android – Services and concurrency PART 3</span>, KandZ

+ –

  • 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


94680cookie-checkAndroid – Services and concurrency PART 3Android – Services and concurrency PART 3

Related posts