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
7
votes
1 answer

null intent redelivered to Service onStartCommand()

In the Android documentation, the Service's "onStartCommand()" has an intent given as a param, that according to the docs: "the Intent supplied to startService(Intent), as given. This may be null if the service is being restarted after its process…
7
votes
2 answers

Unable to find explicit activity class {}; have you declared this activity in your AndroidManifest.xml

I'm trying unzip some files in background, so I use IntentService like in google's tutorial. My service class declared in AndroidManifest like this:
tonyAndr
  • 177
  • 1
  • 3
  • 10
6
votes
2 answers

Nearby Messages using an IntentService

Initially I setup a BroadcastReceiver to receive intents from the Nearby Messages API. class BeaconMessageReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { …
Bryan
  • 14,756
  • 10
  • 70
  • 125
6
votes
4 answers

Run a service in background continuously

Run a service in background continuously. For example, a service has to be kicked off which will display a toast message 20 seconds once even if the app is closed. public class AppService extends IntentService { public int onStartCommand(Intent…
Jayavinoth
  • 544
  • 1
  • 9
  • 24
6
votes
1 answer

Android IntentService triggered with null intent

I'm seeing a crash in Crashlytics: Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Intent.getIntExtra(java.lang.String, int)' on a null object reference at…
JY2k
  • 2,879
  • 1
  • 31
  • 60
6
votes
3 answers

startActivity() doesn't work when app is in background (In this special case)

I'm trying to bring my app from background to foreground. In onHandleIntent() of my custom IntentService class, I have: Intent intent = new Intent(); intent.setClass(getApplicationContext(), MainActivity.class); // Also tried with "this" instead of…
6
votes
2 answers

IntentService - find number of Intents waiting in the queue

In my app I use an IntentService to do some work. I want to find out how many intents are waiting to be processed, as IntentService holds them in a 'work queue' , and sends the next one to onStartCommand() as the onStartCommand of the previous one…
Jonas Czech
  • 12,018
  • 6
  • 44
  • 65
6
votes
2 answers

Android: How to determine if IntentService is running?

I have an activity for upload from which I am calling Intent service. In there I am handling the API request call. I want an activity to know whether the service is running or not, to show an uploading tag. I tried following to determine if the…
6
votes
1 answer

How to start an IntentService from a WakefulBroadcastReceiver

I have an application, which you should be able to recreate entirely and very easily with the code I'll post in this question. Here's the Manifest file:
overactor
  • 1,759
  • 2
  • 15
  • 23
5
votes
2 answers

Geofence works but after a while stops triggering

My Geofence is working at start but then all of a sudden after a day or two stops triggering, is there a problem on Google side here or my code? Upon boot and starting the app I use an IntentService that then registers a Geofence: public class…
5
votes
4 answers

Login Screen showing progressdialog and allow screen orientation change

Hello i am trying to implement a log in screen showing a progress dialog and allowing the phone to rotate. I want to ask what is the best way to do that (IntentService, AsyncTask,Service) and allowing the phone to rotate? I read a lot answers…
g.y
  • 59
  • 1
5
votes
0 answers

Android IntentService's onDestroy not called in foreground IntentService

I have an IntentService. In its OnCreate I call startForeground(1, buildUpdatingAssignmentsNotification()); @NonNull private Notification buildUpdatingAssignmentsNotification() { NotificationCompat.Builder notificationBuilder = new…
TomerZ
  • 615
  • 6
  • 17
5
votes
2 answers

Are separate intent services queued on the same thread?

I have two intent services - IntentServiceA and IntentServiceB They have the following class definitions: public class FirstService extends IntentService { public FirstService() { super("first_service"); } @Override protected void…
5
votes
2 answers

Android - Running a IntentService multiple times

So I have a IntentService that runs fine when I run it a single time. It takes an image manipulates it then outputs a series of RGB values. But what I now need it to do is run multiple times to batch out a series of images. My first attempt…
Mytheral
  • 3,929
  • 7
  • 34
  • 57
5
votes
1 answer

Best approach to execute service in Android

I have a service that have an variable life time. It may execute from 5 minutes to 2 hours (for example). So I'm looking for the best approach to do that, and my service must achieve the following features: Send (to my server) lat-long every 5…
1 2
3
30 31