My new Android application, Vault 3 for Android, is advertisement-supported. The ad provider is AdMob. This blog post describes the code I wrote to integrate AdMob advertisements with my application.
I added a <LinearLayout> with an id of "adLayout" for the banner ad in Vault 3's main activity (see below). The main activity's onCreate method calls my addAds method, which creates an AdView and attaches it to the <LinearLayout>. Then it arranges for the ad to be updated every minute by instantiating and running the updateAdTask. The updateAdTask changes the ad, and then arranges to run again in 60 minutes (60,000 milliseconds).
Vault3.java:
package com.ericbt.Vault3;
...
public class Vault3 extends TabActivity {
private Handler adTimerHandler = new Handler();
private AdView adView;
...
private Runnable updateAdTask;
@Override
public void onCreate(Bundle savedInstanceState) {
...
setContentView(R.layout.main);
...
addAds();
...
}
private void addAds() {
// Create the adView
adView = new AdView(this, AdSize.BANNER, {adUnitId});
LinearLayout layout = (LinearLayout)findViewById(R.id.adLayout);
layout.addView(adView);
updateAdTask = new Runnable() {
@Override
public void run() {
changeAd();
// Request a new ad every 60 seconds.
adTimerHandler.postDelayed(this, 1000 * 60);
}
};
updateAdTask.run();
}
public void changeAd() {
...
// Initiate a generic request to load it with an ad
adView.loadAd(new AdRequest());
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/adLayout"
>
</LinearLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"
>
</FrameLayout>
</LinearLayout>
</TabHost>
Postscript: My experience with AdMob was disappointing. The ads simply didn't perform as well as I had hoped. I ended up replacing AdMob ads with a large "upgrade" button in the free version of Vault 3 for Android.
| Title | Date |
| Node.js + Express: How to Block Requests by User-Agent Headers | January 7, 2026 |
| Vault 3 is Now Available for Windows on ARM Machines! | December 13, 2025 |
| Vault 3: How to Include Outline Text in Exported Photos | October 26, 2025 |
| .NET Public-Key (Asymmetric) Cryptography Demo | July 20, 2025 |
| Raspberry Pi 3B+ Photo Frame | June 17, 2025 |
| EBTCalc (Android) Version 1.53 is now available | May 19, 2024 |
| Vault 3 Security Enhancements | October 24, 2023 |