Detecting other apps is open? (Android)

I just wondering how can we detect if other app is open on top of our current app?
For example, a user opens up the Native Music player. How do we detect that?

I wanna stop the music playing in my app when the Native Music player is open.
Is there a way to detect that?

Thanks.

FaRHaN

You didn’t mentioned platform on which you want to use this trick.

Android and iOS don’t allow you just monitor list of launched apps: probably programmer can use special permission in AndroidManifest, and it’s just impossible in iOS. I highly recommend to not implement this for android because users don’t like apps that ask too much permissions.

However, there are standard ways to detect sleep/resume event in cocos2dx app delegate: just pause music when app comes to sleep an unpause when user touches screen anywhere after sleep.

P.S. unpause on touch is recommended way to unpause music on android: http://android-developers.blogspot.ru/2011/11/making-android-games-that-play-nice.html

Hi Sergey,

I believe through Cocos-2dx I can detect if the app is pause or unpause; but, the problem is I cant’s detect if another app pops up over my app, like the Android’s Native Music player since my app is still running in the back.

The question is how can we detect if the Native music player is currently open? I notice that some games will stop its background music when I open up the native music player. I just wondering how can i do the same?

Thanks,
FaRHaN

Sergey Shambir wrote:

You didn’t mentioned platform on which you want to use this trick.
>
Android and iOS don’t allow you just monitor list of launched apps: probably programmer can use special permission in AndroidManifest, and it’s just impossible in iOS. I highly recommend to not implement this for android because users don’t like apps that ask too much permissions.
>
However, there are standard ways to detect sleep/resume event in cocos2dx app delegate: just pause music when app comes to sleep an unpause when user touches screen anywhere after sleep.
>
P.S. unpause on touch is recommended way to unpause music on android: http://android-developers.blogspot.ru/2011/11/making-android-games-that-play-nice.html

Ok, on android there are two ways to track such event in activity. Activity class reference in docs covers both cases: http://developer.android.com/reference/android/app/Activity.html

At first, onPause() and onResume() Java methods called when another apps appears on top of current app, and only onStart() and onStop() actually called when app comes to sleep and then resumes. Actually there’re no garantues that onStop() will be called whenever — as android developers blog post tells.

There is also method onWindowFocusChanged() in Activity class, system window that changes volume settings causes losing focus for underlying apps.