0

A client of mine has some proprietary android devices that he needs to lock the settings for. Basically he wants a service that will detect when the settings activity is in the foreground and switch to a "type your password" activity which will then allow the settings app to be run if the password is correct.

My question is simply how can I detect when another application is in the foreground? As a follow-up, is there a simple way to bring my application to the front when this is detected?

Caleb Cameron
  • 181
  • 1
  • 15
  • This is maybe something http://stackoverflow.com/questions/8489993/check-android-application-is-in-foreground-or-not – m.Ling Dec 19 '13 at 16:23

1 Answers1

0

There is ActivityLifecycleCallbacks class for Android 4.0 and higher. You register this listener in your Application class and it will be notified about every activity started. You can implement a counter for all started activities and if at least one activity is started, the app is foreground.

For older devices every activity needs to call a callback method of Application to report that it was started.

sergej shafarenka
  • 20,071
  • 7
  • 67
  • 86