Android根据上下文对象Context找到对应的Activity

Android根据上下文对象Context找到对应的Activity:

    @Nullable
    public static Activity findActivity(Context context) {
        if (context instanceof Activity) {
            return (Activity) context;
        }
        if (context instanceof ContextWrapper) {
            ContextWrapper wrapper = (ContextWrapper) context;
            return findActivity(wrapper.getBaseContext());
        } else {
            return null;
        }
    }

你可能感兴趣的:(android,备忘,android,context,activity)