7

Possible Duplicate:
Android: How can I get the current foreground activity (from a service)?

In a method I have to know which activity is on the screen. How do I get the current activity?

Community
  • 1
  • 1
Gerhard
  • 111
  • 1
  • 1
  • 7

2 Answers2

5

Sometimes Fragments need to know which Activity they belong to. For this, use Fragment.getActivity(). This works since API 11.Refer this

Sparky
  • 8,437
  • 1
  • 29
  • 41
0

How do I get the current activity

You don't. There may not be a "current activity".

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Even if there might not be a current activity, it would be nice to be able to determine if there was once or not. What I'd like to be able to determine is which of my activities is active, if any. – ThomasW May 27 '15 at 03:32