Skip to content

Instantly share code, notes, and snippets.

@kingargyle
Created September 21, 2016 13:48
Show Gist options
  • Save kingargyle/65f42ee1c4be4dee816115d6c68e809c to your computer and use it in GitHub Desktop.
Save kingargyle/65f42ee1c4be4dee816115d6c68e809c to your computer and use it in GitHub Desktop.
Retrieve an Activity from a ContextWrapper
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