Last active
January 29, 2017 09:52
-
-
Save Manabu-GT/f4493205573a1e6441e2dbc191c0da63 to your computer and use it in GitHub Desktop.
Get an Activity Context within a View
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Activity getActivity() { | |
Context context = getContext(); | |
while (context instanceof ContextWrapper) { | |
if (context instanceof Activity) { | |
return (Activity)context; | |
} | |
context = ((ContextWrapper)context).getBaseContext(); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment