Skip to content

Instantly share code, notes, and snippets.

@achenglike
Created April 25, 2018 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achenglike/cd2d4a0dfc5e98cb7b7ed65843754aeb to your computer and use it in GitHub Desktop.
Save achenglike/cd2d4a0dfc5e98cb7b7ed65843754aeb to your computer and use it in GitHub Desktop.
get activity from context
/**
* get Activity from context
* @param context
* @return
*/
public static Activity getActivity(Context context) {
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