Search This Blog

Tuesday, 30 December 2014

Best practices Android Resposiveness : Using background Intent service for background job

An IntentService isn't affected by most user interface lifecycle events, so it continues to run in circumstances that would shut down an AsyncTask.

Creating a background services

Create a class RSSPullService and extends IntentService to create component IntentService

          public class RSSPullService extends IntentService {
    protected void onHandleIntent(Intent workIntent) {
        // Gets data from the incoming Intent
        String dataString = workIntent.getDataString();
        // Do work here, based on the contents of dataString

Define IntentService with application Manifest

Create a background work request and send it to IntentService

Create a new, explicit Intent for the IntentService called RSSPullService.

mServiceIntent = new Intent(getActivity(), RSSPullService.class);

Call startService()

// Starts the IntentService

Report Status from an IntentService See Google Android Article 

Download Source

Android News and source code