Stopping all services..

by greggnic » Fri, 10 Apr 2009 01:40:20 GMT

Sponsored Links

I just started writing an application for android and have run into a
wall. I would like my program to wait a certain amount of time and
then stop all currently running services. This would be useful when
falling asleep and you want to listen to music for say 30 minutes and
then the music player turns off automatically. I have tried this bit
of code:

                ActivityManager am = (ActivityManager)

                List<ActivityManager.RunningServiceInfo> myList =

                for(int i=0; i < myList.size(); i++){

                        //Toast.makeText(context, myList.get(i).process,

However, this does not work. Does anyone have a better way to do this
or any suggestions? Thanks,



Stopping all services..

by Mark Murphy » Fri, 10 Apr 2009 06:12:08 GMT


IMHO, that would be a rather significant security issue.

Mark Murphy (a Commons Guy)  | 

Android App Developer Books: 


Sponsored Links

Stopping all services..

by greggnic » Fri, 10 Apr 2009 07:45:38 GMT

 I see your point and definitely agree. I would really like to see a
sleep timer function for the music player though and don't think I
would be able to write a whole music player application that could
compete with the others out there...


Stopping all services..

by Mark Murphy » Fri, 10 Apr 2009 08:17:39 GMT


Well, the built-in music player is open source: ;a=tree

In principle, you could make a sleep-timer patch and submit it: 

Admittedly, there is a learning curve for making changes to the source
code, more so than with many open source projects, due to the unusual
build environment and the unusual patch submission process. I haven't
climbed that curve myself.

Another possibility would be for you to create an application that let
users configure sleep timers and, when the timer elapsed, broadcast an
Intent that confirming applications would pay attention to and honor.
You might partner with, as this seems like their sort of
application, and you might be able to help get some prominent
third-party applications, such as some music players, to honor your
sleep-timer Intent. This requires as much people skills as coding
skills, though, to convince other developers to follow your sleep-timer

There are probably other ways to go about this as well -- those are just
two off the top of my head.

Mark Murphy (a Commons Guy)  | 

_The Busy Coder's Guide to Android Development_ Version 2.0 Available!


Other Threads

1. Creating views dynamically

Hi all. Need some help with Views...

In my main.xml layout file, I define a FrameLayout. Then in another
layout file (say overlay.xml), I define another layout.

At runtime (onCreate) I want to create a new View object, set it's
layout with overlay.xml, and add it to the frame dynamically. I need
access to the elements of the overlay, to change text etc.

Is this possible? Any help appreciated!


2. Sorry Cannot Play this Video

trying to play video in a Emulator, "error" Sorry this Video cannot be
played" , please tell me what i am doing or not doing..




import android.os.Bundle;
import android.util.Log;
import android.widget.MediaController;
import android.widget.VideoView;

public class XSO5 extends Activity {
        private static final String RTSP ="

        VideoView videoXSO5;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

      //***VideoView to video element inside Multimedia.xml file

       VideoView videoView =(VideoView)findViewById(;
       Log.v("videoXSO5", "***Video to Play:: " + RTSP);
       MediaController mc = new MediaController(this);
       Uri video = Uri.parse(RTSP);


3. Flickering camera preview in SurfaceView

4. Market T Mobile Carrier Billing

5. Getting hold of PreferenceActivity Views from the xml file

6. Updating my calendar

7. Cannot build Android source in Ubuntu