1

Is there a way to find the app whose activity is currently active in android? Does android send a broadcast when a new app/activity is active?

Diji
  • 11
  • 1
  • 2

1 Answers1

5

Call ActivityManager.getRunningAppProcesses(), then iterate through the ActivityManager.RunningAppProcessInfo objects and look for the one(s) with IMPORTANCE_FOREGROUND.

I'm not sure if there are situations (tablet? Laptop dock?) when you can have multiple foreground activities.

EboMike
  • 76,846
  • 14
  • 164
  • 167
  • Thanks a lot. I'd still like to know though if there is any broadcast sent when a new activity or package comes to foreground – Diji Mar 22 '11 at 20:01
  • Highly doubt it. Maybe an undocumented one, but you shouldn't use those anyway since they are bound to change. – EboMike Mar 22 '11 at 21:40