Service- Does it serves as a background thread?

Posted on Updated on

Services are one of the important application components in Android that helps to execute long running operations in background. In fact what I thought was, Services would execute as a background thread without interrupting the main thread. But soon I found that my assumption was wrong, in fact Service also run in the main thread of the application  where the UI operations occur. Therefore, if we perform a long task in onStartCommand() method, it will block the main thread the end result is, unresponsive application . So to avoid the problem, you have to execute the complex task into a separate thread. this can be achieved with the help of

  • Asynctask
  • Declaring seperate Thread

Additionally there two memory management techniques as well. Declaring the return statement in onStartCommand() method.

START_STICKY: Notifies the OS to recreate the service after it has enough memory and call onStartCommand() again with a null intent.

START_NOT_STICKY: Notifies the OS  not to recreating the service again.

3 thoughts on “Service- Does it serves as a background thread?

    IT services in toronto said:
    April 19, 2013 at 1:44 am

    After exploring a number of the blog posts on your
    web page, I honestly like your way of writing a blog.
    I saved it to my bookmark site list and will be checking back in the near future.
    Take a look at my web site as well and let me know how you feel.

    go thorugh said:
    April 20, 2013 at 9:15 am

    An impressive share! I have just forwarded this onto a colleague
    who was doing a little research on this. And he in fact
    ordered me dinner simply because I discovered it for him.
    .. lol. So allow me to reword this…. Thanks for the
    meal!! But yeah, thanx for spending some time to discuss this subject here on
    your web page.

    go thorugh said:
    May 22, 2013 at 7:25 pm

    Hello, yes this article is in fact fastidious and I have learned lot of things from it about blogging.

    thanks.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s