/**
* Get the Activity of a context. This is typically used to determine the hosting activity of a
* {@link View}
*
* @param context The context
* @return The Activity or throws an Exception if Activity couldnt be determined
*/
@NonNull public static Activity getActivity(@NonNull Context context) {
if (context == null) {
throw new NullPointerException("context == null");
}
if (context instanceof Activity) {
return (Activity) context;
}
while (context instanceof ContextWrapper) {
if (context instanceof Activity) {
return (Activity) context;
}
context = ((ContextWrapper) context).getBaseContext();
}
throw new IllegalStateException("Could not find the surrounding Activity");
}
PresenterManager.java 文件源码
java
阅读 38
收藏 0
点赞 0
评论 0
项目:GitHub
作者:
评论列表
文章目录