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 {
    @Override
    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);
mServiceIntent.setData(Uri.parse(dataUrl));

Call startService()

// Starts the IntentService
getActivity().startService(mServiceIntent);

Report Status from an IntentService See Google Android Article 

Download Source


No comments:

Post a Comment

Feedback always help in improvement. If you have any query suggestion feel free to comment and Keep visiting my blog to encourage me to blogging

Android News and source code