An IntentService isn't affected by most user interface lifecycle events, so it continues to run in circumstances that would shut down an AsyncTask.
mServiceIntent = new Intent(getActivity(), RSSPullService.class);
mServiceIntent.setData(Uri.parse(dataUrl));
Call startService()
// Starts the IntentService
getActivity().startService(mServiceIntent);
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);
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