Questions tagged [android-service]

A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use.

A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use. Each service class must have a corresponding declaration in its package's AndroidManifest.xml. Services can be started with Context.startService() and Context.bindService().

Android Service Class Reference

Tutorials & Examples

6538 questions
991
votes
31 answers

How to check if a service is running on Android?

How do I check if a background service is running? I want an Android activity that toggles the state of the service -- it lets me turn it on if it is off and off if it is on.
Bee
  • 13,607
  • 6
  • 31
  • 48
796
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
  • 12,799
  • 11
  • 54
  • 87
589
votes
9 answers

Example: Communication between Activity and Service using Messaging

I couldn't find any examples of how to send messages between an activity and a service, and I have spent far too many hours figuring this out. Here is an example project for others to reference. This example allows you to start or stop a service…
Lance Lefebure
  • 6,735
  • 6
  • 21
  • 18
435
votes
4 answers

getApplication() vs. getApplicationContext()

I couldn't find a satisfying answer to this, so here we go: what's the deal with Activity/Service.getApplication() and Context.getApplicationContext()? In our application, both return the same object. In an ActivityTestCase however, mocking the…
Matthias
  • 41,630
  • 28
  • 100
  • 129
414
votes
18 answers

Android 8.0: java.lang.IllegalStateException: Not allowed to start service Intent

On application launch, app starts the service that should to do some network task. After targeting API level 26, my application fails to start service on Android 8.0 on background. Caused by: java.lang.IllegalStateException: Not allowed to start …
phnmnn
  • 10,564
  • 9
  • 39
  • 56
337
votes
16 answers

Trying to start a service on boot on Android

I've been trying to start a service when a device boots up on android, but I cannot get it to work. I've looked at a number of links online but none of the code works. Am I forgetting something? AndroidManifest.xml
Alex
  • 3,657
  • 5
  • 17
  • 10
296
votes
6 answers

Get Context in a Service

Is there any reliable way to get a Context from a Service? I want to register a broadcast receiver for ACTION_PHONE_STATE_CHANGED but I don't need my app to always get this information, so I don't put it in the Manifest. However, I can't have the…
user123321
  • 12,025
  • 11
  • 49
  • 63
285
votes
4 answers

START_STICKY and START_NOT_STICKY

What is the difference between START_STICKY and START_NOT_STICKY while implementing services in android? Could anyone point out to some standard examples.. ?
prago
  • 4,425
  • 5
  • 21
  • 27
263
votes
26 answers

Android Fatal signal 11 (SIGSEGV) at 0x636f7d89 (code=1). How can it be tracked down?

I've been reading the other posts on tracking down the reasons for getting a SIGSEGV in an Android app. I plan to scour my app for possible NullPointers related to Canvas use, but my SIGSEGV barfs up a different memory address each time. Plus I've…
dubmojo
  • 5,753
  • 8
  • 36
  • 61
257
votes
13 answers

How to have Android Service communicate with Activity

I'm writing my first Android application and trying to get my head around communication between services and activities. I have a Service that will run in the background and do some gps and time based logging. I will have an Activity that will be…
Scott Saunders
  • 27,788
  • 14
  • 52
  • 63
229
votes
5 answers

Permission Denial: startForeground requires android.permission.FOREGROUND_SERVICE

Lately we have suddenly been seeing a few of the following stack traces. Why could that be? This is from when the app tries to move an audio commentary service into the foreground with a media notification and…
Roy Solberg
  • 14,329
  • 9
  • 39
  • 68
164
votes
10 answers

Android – Listen For Incoming SMS Messages

I am trying to create an application for monitoring incoming SMS messages, and launch a program via incoming SMS, also it should read the content from the SMS. Workflow: SMS sent to Android device self executable Application Read the SMS…
iShader
  • 1,955
  • 4
  • 17
  • 17
158
votes
7 answers

android start activity from service

Android: public class LocationService extends Service { @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); startActivity(new Intent(this, activity.class)); } } I launched this…
d-man
  • 53,999
  • 81
  • 200
  • 285
149
votes
6 answers

Difference between Service, Async Task & Thread?

What is the difference between Service, Async Task & Thread. If i am not wrong all of them are used to do some stuff in background. So, how to decide which to use and when?
SpunkerBaba
  • 2,097
  • 4
  • 18
  • 12
146
votes
3 answers

Exported service does not require permission: what does it mean?

I created a service that is bound by other applications through AIDL, and I add it to the manifest as follows:
enzom83
  • 7,500
  • 8
  • 55
  • 107
1
2 3
99 100