package com.jmlb0003.jokes.gradlejokesproject;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

import butterknife.ButterKnife;
import butterknife.OnClick;

public final class MainActivityFragment extends Fragment {

    private Callback callback;

    @Override
    public View onCreateView(
            final LayoutInflater inflater,
            final ViewGroup container,
            final Bundle savedInstanceState) {

        View root = inflater.inflate(R.layout.fragment_main, container, false);
        ButterKnife.bind(this, root);
        callback = (Callback) getActivity();
        AdView mAdView = (AdView) root.findViewById(R.id.adView);
        // Create an ad request. Check logcat output for the hashed device ID to
        // get test ads on a physical device. e.g.
        // "Use AdRequest.Builder.addTestDevice("ABCDEF012345") to get test ads on this device."
        AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .build();
        mAdView.loadAd(adRequest);
        return root;
    }

    @OnClick(R.id.tell_joke_button)
    public void tellJoke() {
        callback.goToJokeActivity(Joker.getJoke());
    }

    interface Callback {

        void goToJokeActivity(String joke);

    }

}

@@ -613,16 +613,22 @@
         
+final 
 View roo
@@ -691,16 +691,43 @@
 false);%0A
+        initAddView(root);%0A
         
@@ -813,17 +813,255 @@
     
-AdView mA
+setRetainInstance(true);%0A        return root;%0A    %7D%0A%0A    @OnClick(R.id.tell_joke_button)%0A    public void tellJoke() %7B%0A        callback.goToJokeActivity(Joker.getJoke());%0A    %7D%0A%0A    private void initAddView(final View root) %7B%0A        final AdView a
 dVie
@@ -1105,16 +1105,50 @@
 dView);%0A
+        if (adView != null) %7B%0A    
         
@@ -1228,16 +1228,20 @@
         
+    
 // get t
@@ -1283,16 +1283,20 @@
         
+  
+  
 // %22Use 
@@ -1384,16 +1384,26 @@
         
+    final 
 AdReques
@@ -1456,16 +1456,20 @@
         
+   
+ 
 .addTest
@@ -1521,16 +1521,20 @@
         
+    
 .build()
@@ -1547,10 +1547,13 @@
     
-mA
+    a
 dVie
@@ -1582,147 +1582,12 @@
     
-   
-return root;%0A    %7D%0A%0A    @OnClick(R.id.tell_joke_button)%0A    public void tellJoke() %7B%0A        callback.goToJokeActivity(Joker.getJoke());
+   %7D
 %0A   

Refactor MainActivityFragment