Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Service is running, but it doesn't show up in settings -> running services

I have a service in my app, as some other apps have, too. From what I am used to, I can see (and kill) services nicely in settings -> (running) services. But: not mine...

The service itself is extended from IntentService. It is handling Alarm Intents via BroadcastReceiver and also messages from my app and back to do some work. As it's essential to my app and keeps some remote web session and other (read: "a lot of") persistent data, I do explicitly start it in main activity with

startService(new Intent(this, HeartBeatService.class)); 

and in the service, I even use

startForeground(NOTIFY_RUNNING, runNotification);

Other of my apps' activities using the service just using bindService(), working like a charm.

It really is running. Perfectly and always, as I wished, even if the activities get killed by android because of whatever android thinks it's good for.

Just: I don't "see" it running. I also tried overrriding the service onStartCommand() to return START_STICKY, but nothing changed. I know, this one should not be overwritten in IntentService.

Or am I just thinking wrong somehow? Is IntentService "different"?

Thank you!

like image 781
Oliver Avatar asked Dec 08 '11 19:12

Oliver


People also ask

How do I know if my Android service is running?

You can do this by making your own Interface where you declare for example " isServiceRunning() ". You can then bind your Activity to your Service, run the method isServiceRunning(), the Service will check for itself if it is running or not and returns a boolean to your Activity.

How do I trigger a service in Android?

Start a service. An Android component (service, receiver, activity) can trigger the execution of a service via the startService(intent) method. // use this to start and trigger a service Intent i= new Intent(context, MyService. class); // potentially add data to the intent i.

How do I keep a service running on Android?

This example demonstrates how do I run an android service always in background. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.


1 Answers

From the Android documentation reference:

IntentService is a base class for Services that handle asynchronous requests (expressed as Intents) on demand. Clients send requests through startService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.

Your service will only run when it receives an intent and stops once it is done doing what that intent had it do.

Also, I've found that services bound to activities will not show up in the running services screen.

Once you remove the binding, they show up.

like image 186
jawsware Avatar answered Oct 26 '22 20:10

jawsware