Diji
Diji

Reputation: 11

How to programmatically determine the currently active App in Android

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?

Upvotes: 1

Views: 7394

Answers (1)

EboMike
EboMike

Reputation: 77752

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.

Upvotes: 5

Related Questions