Code example for Fragment

Methods: getActivity, onAttach

    public void onAttach(Activity activity) {
        // This is the fragment that launches the Janrain sharing dialogue 
        // If Android restarts the app and restores the activity stack with this fragment 
        // on top then the Janrain library needs to be re-initialized. 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (container == null) {
            // We have different layouts, and in one of them this 
            // fragment's containing frame doesn't exist.  The fragment 
            // may still be created from its saved state, but there is 
            // no reason to try to create its view hierarchy because it 
            // won't be displayed.  Note this is not needed -- we could