Code example for Fragment

Methods: onSaveInstanceState, setUserVisibleHint

0
     * http://stackoverflow.com/questions/8748064/starting-activity-from 
     * -fragment-causes-nullpointerexception 
     */ 
    @Override 
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        setUserVisibleHint(true);
    } 
 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mActivity = getActivity();
 
        LinearLayout layout = new LinearLayout(mActivity);
 
        HtmlTextView text = new HtmlTextView(mActivity);
 
        // padding 
        int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, mActivity
                .getResources().getDisplayMetrics());
        text.setPadding(padding, padding, padding, 0);