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);
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

THE END!!!

Android – Services and concurrency PART 3

Read More

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s