Questions tagged [android-intentservice]

The IntentService class provides a straightforward structure for running an operation on a single background thread.

The IntentService class provides a straightforward structure for running an operation on a single background thread. This allows it to handle long-running operations without affecting your user interface's responsiveness. Also, an IntentService isn't affected by most user interface lifecycle events, so it continues to run in circumstances that would shut down an AsyncTask

An IntentService has a few limitations:

  • It can't interact directly with your user interface. To put its results in the UI, you have to send them to an Activity.
  • Work requests run sequentially. If an operation is running in an IntentService, and you send it another request, the request waits until the first operation is finished.
  • An operation running on an IntentService can't be interrupted.

However, in most cases an IntentService is the preferred way to simple background operations.

461 questions
823
votes
11 answers

Service vs IntentService in the Android platform

I am seeking an example of something that can be done with an IntentService that cannot be done with a Service (and vice-versa)? I also believe that an IntentService runs in a different thread and a Service does not. So, as far as I can see,…
roiberg
  • 13,629
  • 12
  • 60
  • 91
143
votes
8 answers

What is the difference between an IntentService and a Service?

Can you please help me understand what the difference between an IntentService and a Service is?
michael
  • 106,540
  • 116
  • 246
  • 346
52
votes
5 answers

android design considerations: AsyncTask vs Service (IntentService?)

I'm designing an android app which will need to do the following steps: user pushes a button or otherwise indicates to "sync data". sync process will use REST web services to move data to and from the server. the data will be stored locally in a…
tia
  • 1,004
  • 3
  • 16
  • 21
48
votes
5 answers

Android RuntimeException: Unable to instantiate the service

I want to create a service which will run on a separate thread (not on UI Thread), so I implemented a class which will extend IntentService. But I haven't got any luck. Here is the code. public class MyService extends IntentService { public…
ram
  • 3,487
  • 10
  • 33
  • 47
27
votes
2 answers

IntentService's onHandleIntent(Intent) gets null argument

I'm using an IntentService to run a background service for my app on android. Oddly I'm getting a lot of crash reports with cases where the intent passed to onHandleIntent is null. I'm not even sure how this is possible and seems extremely odd. Can…
24
votes
2 answers

Android IntentService can't instantiate class; no empty constructor

I have a MainActivity class that needs to access an online API (thus using network resources). This requires a background thread that I've created in a separate file HttpRequestService.java. MainActivity.java: public class MainActivity extends…
Kyle
  • 1,070
  • 2
  • 13
  • 23
22
votes
2 answers

How to keep an IntentService running even when app is closed?

In my Android app I start an IntentService from within an Activity by calling startService(new Intent(this, MyService.class)); And it works like a charm. I can move between Activies, press the Home button to switch to other apps... and it's still…
fergaral
  • 2,077
  • 6
  • 17
  • 34
18
votes
3 answers

What are differences between JobIntentService and IntentService?

I do not understand what difference between those two APIs. I mean when to use the first one. Why is there JobIntentService ? Thanks in advance
18
votes
3 answers

Realm `access from incorrect thread` error when using shared code between IntentService and AsyncTask (Android)

I have some code that downloads a "Current" object's JSON. But this same code needs to be called by an IntentService whenever an alarm goes off (when the app is not running any UI), and also by an AsyncTask while the app is running. However, I got…
17
votes
1 answer

Android Service extends ResultReceiver for IntentService, how to implement CREATOR?

My app relies on a Service which stays in sync with external hardware in the background. Because the service operates on the main Thread, it does any heavy work asynchronously using an IntentService. Here is a minimalized example of the code to…
16
votes
5 answers

Android: intentservice, how abort or skip a task in the handleintent queue

i have an activity ("ApplicationActivity") that call an intent service ("DownloadService") The intentService download files from internet in background, but i want to be able to abort a specific download......... So let's say that i put 5 files in…
Sgotenks
  • 1,723
  • 4
  • 20
  • 34
16
votes
1 answer

Set "allow" permission by default in "Asus auto start manager" from code

I have an application which needs to run in the background, so I'm using a WakeFullService for that. But in Asus Zenfone it's not working because Auto start manager does not allow the app to run. My expectation is: To set "allow permission" in auto…
15
votes
2 answers

JobIntentService doesn't start immediately on Android 8.0

I have implemented JobIntentService to do some background task which works fine on older Android devices (pre Android O). I see the intent is handled immediately but on Android O device there is some delay before JobIntentService.onHandleWork()is…
Prudhvi
  • 2,276
  • 7
  • 34
  • 54
15
votes
5 answers

Geofencing : HTTP request failed while sending through the background service. Gives UnknownHostException

I implemented Geofence in android application. I followed this link to implement 'Geofence' in app. I am using 'Retrofit' library to call 'HTTP' request. App has following permissions :
14
votes
2 answers

ResultReceiver.send can only be called from same library group

I have an IntentService that is using android.support.v4.os.ResultReceiver to pass data. In the IntentService, when I use ResultReceiver.send method to send the result back, Android Studio shows an error saying ResultReceiver.send can only be…
kp91
  • 1,168
  • 10
  • 14
1
2 3
30 31