Skip to content

Instantly share code, notes, and snippets.

@Manabu-GT
Last active January 29, 2017 09:52
Show Gist options
  • Save Manabu-GT/f4493205573a1e6441e2dbc191c0da63 to your computer and use it in GitHub Desktop.
Save Manabu-GT/f4493205573a1e6441e2dbc191c0da63 to your computer and use it in GitHub Desktop.
Get an Activity Context within a View
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