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
34
votes
3 answers

How to keep a service running in background even after user quits the app?

I am developing an app where I start a service if a particular feature (in my app) is enabled by user. I want to keep running this service even after user quits my app. How can I do this? plz help
Saurabh Agrawal
  • 1,355
  • 3
  • 17
  • 33
34
votes
3 answers

How to simulate touch from background service with sendevent or other way?

Is it possible to simulate touch from the background application (or service) or to run sh script (that simulate touch)? It is needed for testing android system without USB or other connection to PC, thats why I can't (or don' know how) use Monkey…
v1k
  • 1,307
  • 2
  • 15
  • 20
34
votes
5 answers

BroadcastReceiver when wifi or 3g network state changed

I have an app which updates the database whenever the phone is connected to WiFi. I have implemented a Service and BroadcastReceiver which will run the Service (it will tell me what network is in use), but the problem is I don't know what to add in…
J1and1
  • 920
  • 3
  • 12
  • 25
33
votes
8 answers

Android 9 (Pie), Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord

First of all, I looked at these; Context.startForegroundService() did not then call Service.startForeground() Context.startForegroundService() did not then call Service.startForeground Android 9 (Pie) Only: Context.startForegroundService() did not…
Beyazid
  • 1,795
  • 1
  • 15
  • 28
33
votes
2 answers

Create only one instance of Service (Android)

How can I make sure that only one instance of Service is created? I have checked some functions with logging (WeatherService is the class who extends Service): Log.i(TAG, "Start Id:" + WeatherService.this.hashCode()); Log.i(TAG, "End Id:" +…
Torstein I. Bø
  • 1,359
  • 4
  • 14
  • 33
33
votes
6 answers

The process of the service is killed after the application is removed from the application tray

I am starting a service (or re-starting the running service) when an activity is launched, using : Intent intent = new Intent(this, MyService.class); startService(intent); Later on based on certain actions, the same activity binds to the service…
geekoraul
  • 2,623
  • 2
  • 21
  • 33
33
votes
1 answer

Why no Service.onStop method?

I've read a lot around Android service. As I understand, the lifecycle is: void onCreate() void onStart(Intent intent) ... void onDestroy() http://www.linuxtopia.org/online_books/android/devguide/guide/topics/fundamentals.html But there's…
user48956
  • 14,850
  • 19
  • 93
  • 154
32
votes
6 answers

Asynctask vs Thread vs Services vs Loader

I got slightly confused about the differences between Asynctask, Thread, Service, Loader in Android. I know how it works. But i still don't understand what and when should i use. I work with Android for 3 years, and generally still use AsyncTask…
32
votes
7 answers

Start a Service from an Activity

In my app, I have an Activity from which I want to start a Service. Can anybody help me?
MAkS
  • 751
  • 3
  • 10
  • 19
32
votes
4 answers

How to call a method in activity from a service

There is a service that listens for some voice. If voice matches a string a certain method is invoked in the service object. public class SpeechActivationService extends Service { public static Intent makeStartServiceIntent(Context pContext){…
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
32
votes
4 answers

Android Emulator: How can I get a list of services that are running

I have the Android Emulator running in my Ubuntu VM and just installed an apk file trough the console. The emulator and adb have many options to view what is going on on the device. But how can I get a list of services that are currently running?…
Jasi
  • 463
  • 2
  • 5
  • 12
31
votes
9 answers

Huawei device killing my foreground service, even with dontkillmyapp.com's solution

I'm developing an app which is basically a location tracking software. When you start it, it saves locations and sending them to a server. The code is working for like 5 years now without any modification, without any errors. It is implemented with…
Adam Varhegyi
  • 11,307
  • 33
  • 124
  • 222
31
votes
6 answers

Access denied finding property "camera.hal1.packagelist"

While using camera in service mobile screen is getting un-touchable(locked by transparent window ) and only below error is occuring Access denied finding property "camera.hal1.packagelist" what will be the reason and its solution? Please help..
Amin Pinjari
  • 2,129
  • 3
  • 25
  • 53
30
votes
1 answer

Google IO Rest design pattern, finished ContentProvider and stuck on getting the data from the network

After watching the very known video on this topic I decided to go with design pattern B. Using a contentprovider with servicehelper. Basically I have the following files: MyProvider MyDatabase Mycontract In the activity I can now get the…
Sam
  • 2,647
  • 2
  • 20
  • 25
30
votes
3 answers

Android Pie (9.0) WebView in multi-process

Starting Android Pie (API 28), Google isn't allowing using a single WebView instance in 2 different processes. Documentation: https://developer.android.com/reference/android/webkit/WebView.html#setDataDirectorySuffix(java.lang.String) As required, I…
Lior Iluz
  • 26,213
  • 16
  • 65
  • 114