Skip to content

Instantly share code, notes, and snippets.

@venshine
Last active March 19, 2020 06:52
Show Gist options
  • Save venshine/9944be33383c4ce7f13ed4f17aa5db92 to your computer and use it in GitHub Desktop.
Save venshine/9944be33383c4ce7f13ed4f17aa5db92 to your computer and use it in GitHub Desktop.
判断用于Glide的Context是否有效
/**
* 判断用于Glide的Context是否有效
*
* @param context 用于Glide的Context
* @return 用于Glide的Context是否有效
*/
public static boolean isValidContext(final Context context) {
if (context == null) {
return false;
}
if (context instanceof Activity) {
final Activity activity = (Activity) context;
return !activity.isDestroyed() && !activity.isFinishing();
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment