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

6696 questions
56
votes
6 answers

Continue Service even if application is cleared from Recent app

I am having a little issue. In my application, a Service is started after user is logged in successfully. Previously, the service needed to stop if application was killed. (say, removed from Recent application list by swiping.) So we had used…
MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
52
votes
4 answers

START_STICKY does not work on Android KitKat

One of my apps has a backgrouod service that uses the START_STICKY return code from onStartCommand to automatically restart when the system kills it. It seems that this is no longer working on Android KitKat. Is there any solution for this ? Should…
Muzikant
  • 8,070
  • 5
  • 54
  • 88
52
votes
6 answers

Can I get data from shared preferences inside a service?

I'm developing an android application. I'm using android 2.2 In my application I am capturing GPS data and sending it to service with the 1 hour time interval. If user exits from application it's also working (it is required). I'm using 2 services…
51
votes
3 answers

Minimal android foreground service killed on high-end phone

I'm trying to create an app that lets users log routes (locations/GPS). To ensure locations are logged even when the screen is off, I have created a foreground service for the location logging. I store the locations in a Room Database which is…
50
votes
11 answers

How can we prevent a Service from being killed by OS?

I am using Service in my application and it needs to run until my application is uninstalled, but the problem is it gets killed by OS. How can we prevent it from being killed by OS? Or if it gets killed can we restart that service again through…
Rahul
  • 757
  • 2
  • 8
  • 13
50
votes
9 answers

Check if Activity is running from Service

How can a Service check if one of it's application's Activity is running in foreground?
Taranfx
  • 10,361
  • 17
  • 77
  • 95
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
47
votes
15 answers

Bad notification posted - Couldn't expand RemoteViews for: StatusBarNotification

I am trying to post a notification with a custom view in the notification area from an IntentService, and getting the Couldn't expand RemoteView error. Here's what I am doing in onCreate(): mNotificationManager = (NotificationManager)…
Chaitanya
  • 2,039
  • 4
  • 25
  • 32
46
votes
2 answers

How to address android lint complaint about exported Firebase Messaging service implementations?

Following the Google developer instructions on implementing Firebase in my app, I notice that android lint complains. The idea is that we have to implement two services which inherit from Firebase services: public class MyFirebaseInstanceIDService…
44
votes
2 answers

Android O Replacement for getRunningServices

In previous versions of Android, I used this method to find if a service from another app was up and running. It worked reliably for me: ActivityManager manager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE); List
JoeyG
  • 611
  • 6
  • 14
44
votes
1 answer

Android: When to use Service vs Singleton?

I'm quite new to Android development. When is it a good idea to create an Android Service instead of just using a simple Singleton class? Take, for example, the data layer downloading information feeds from the internet. Using a Service seems too…
chakrit
  • 61,017
  • 25
  • 133
  • 162
43
votes
3 answers

Get rid of "Exported service does not require permission" warning

I'm looking for a solution to get rid of the warning. I don't understand even why it appears. I took a look at a SDK example where no warning appears. At first here is my manifest where I get the warning Exported service does not require…
rekire
  • 47,260
  • 30
  • 167
  • 264
43
votes
5 answers

how to prevent service to run again if already running android

On click of a button I want to start service using method startService(new Intent(currentActivity.this,MyService.class)) but if service is running I don't want to call this method to avoid run service that is already running.How this is possible.I…
Atul Bhardwaj
  • 6,647
  • 5
  • 45
  • 63
41
votes
7 answers

Using Job Scheduler in Android API <21

I was looking at a scheduling tutorial by Vogella. It mentions the Job Scheduler API that was introduced in API 21 of Android. My question is can it be implemented in APIs lower than 21 (Lollipop) but not less than Android version 3 (Honeycomb)?
Manny265
  • 1,709
  • 4
  • 23
  • 42
41
votes
3 answers

Android Library Manifest vs. App Manifest

I've read similar questions here, but am still not clear on a couple of things. Using a Library Project means that my overall project will have two manifests -- one for the library and the other for the "main" app project -- and I'm not clear what…