public Activity getActivity ( ) { Context context = getContext ( ) ; while ( ! ( context instanceof Activity ) && context instanceof ContextWrapper ) context = ( ( ContextWrapper ) context ) . getBaseContext ( ) ; if ( ! ( context instanceof Activity ) ) throw new IllegalStateException ( "Expected an activity context, got " + context . getClass ( ) . getSimpleName ( ) ) ; return ( Activity ) context ; }
Returns the unwrapped activity of the view or throws an exception .