PDA

View Full Version : How to make a Service run ONLY when no other app is running?


lgmcben
11-16-2008, 11:56 PM
I've successfully created a service that change the wallpaper every 2 seconds.

My next goals:

I want this service to...

- auto-stop itself when user launch other app.
- auto-start itself when the wallpaper is visible. (eg. when users close all other apps)

The only clue I have is, when user press the device's "home" button, Android will launch an activity of category "Android.intent.category.HOME".

Which can help me a bit but obviously not enough (as pressing back button also make wallpaper visible, but no event fired)

Any recommendations are welcome.

Thank you in advance. http://www.anddev.org/images/smiles/smile.png

unseen
11-17-2008, 12:19 AM
Just wondering, but what's the point of the wallpaper changing so fast?

lgmcben
11-17-2008, 12:32 AM
Just wondering, but what's the point of the wallpaper changing so fast?

Actually it's a .PNG images extracted from an animated .GIF files.

The purpose is to animate the wallpaper. =)

Actually I'm writing this code for my friend who want the app to behave this way.

Bratag
11-18-2008, 08:02 AM
The only thing I can think of is use the

ActivityManager mAct = (ActivityManager) getSystemService(ACTIVITY_SERVICE);

type of thing and count the number of apps every time the service cycles. If the number increases then stop the cycle. Obviously STOPPING the service means it wont pick back up again after the other app is closed.