Back to project page hpush.
The source code is released under:
MIT License
If you think the Android project hpush listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.hpush.app.fragments; //ww w . j a v a 2s .co m import android.os.Bundle; import android.support.v4.app.Fragment; 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 com.hpush.R; /** * A {@link android.support.v4.app.Fragment} for AdMob. * * @author Xinyue Zhao */ public final class AdFragment extends Fragment { /** * Main layout for this component. */ private static final int LAYOUT = R.layout.fragment_ad; private AdView mAdView; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(LAYOUT, container, false); } @Override public void onActivityCreated(Bundle bundle) { super.onActivityCreated(bundle); mAdView = (AdView) getView().findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); } /** * Called when leaving the activity. */ @Override public void onPause() { if (mAdView != null) { mAdView.pause(); } super.onPause(); } /** * Called when returning to the activity. */ @Override public void onResume() { super.onResume(); if (mAdView != null) { mAdView.resume(); } } /** * Called before the activity is destroyed. */ @Override public void onDestroy() { if (mAdView != null) { mAdView.destroy(); } super.onDestroy(); } }