Download File
Download Project
Settings
Line Wrap
Themes
default
ambiance
bespin
dracula
eclipse
material
mbo
mdn-like
neat
solarized dark
ttcn
zenburn
MyActivity.java
/* * Copyright (C) 2013 Google, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.android.gms.example.bannerexample; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import com.google.android.gms.ads.doubleclick.PublisherAdRequest; import com.google.android.gms.ads.doubleclick.PublisherAdView; /** * Main Activity. Inflates main activity xml and child fragments. */ public class MyActivity extends AppCompatActivity { private PublisherAdView mAdView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); // Gets the ad view defined in layout/ad_fragment.xml with ad unit ID set in // values/strings.xml. mAdView = findViewById(R.id.ad_view); // 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." PublisherAdRequest adRequest = new PublisherAdRequest.Builder().build(); // Start loading the ad in the background. 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(); } }