today:
129
yesterday:
242
Total:
1,004,287

Load an ad

admin 2017.07.21 02:01 Views : 1134

Once the AdView is in place, the next step is to load an ad. That's done with the loadAd() method in the AdViewclass. It takes an AdRequest parameter, which holds runtime information (such as targeting info) about a single ad request.

Here's an example that shows how to load an ad in the onCreate() method of an Activity:

MainActivity.java (excerpt)

package ...

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


public class MainActivity extends AppCompatActivity {
   
private AdView mAdView;

   
protected void onCreate(Bundle savedInstanceState) {
       
super.onCreate(savedInstanceState);
        setContentView
(R.layout.activity_main);

       
MobileAds.initialize(getApplicationContext(),
           
"ca-app-pub-3940256099942544~3347511713");

       
mAdView = (AdView) findViewById(R.id.adView);
       
AdRequest adRequest = new AdRequest.Builder().build();
        mAdView
.loadAd(adRequest);

   
}
   
...
}

That's it! Your app is now ready to display banner ads.

No. Subject Author Date Views
8 Main Activity admin 2017.06.02 32
7 Android options menu tutorial admin 2017.05.17 32
6 Google Map 2 admin 2017.05.29 30
5 Menu admin 2017.06.02 29
4 mnifest solatoz 2017.06.02 28
3 How to make Mobile Web admin 2017.05.08 28
2 How To Create A Simple Web View In Xcode 8 (Swift 3.0) admin 2017.05.21 26
1 Google Map admin 2017.05.29 21