Static ad view

When I developed my drinking game Drunk Green Robots my focus was on making money from in app purchases and not ads. This has worked decently well. I average .10 from each install (I just need more installs to make better money). The way the game is written the user moves between activities pretty quickly and I’m constantly creating new activities and finishing the old ones.

The bad news. This is horrible for ads. I realized this rather quickly and removed ads from all activites except the two that the user is likely to stay on the longest. But still most ads probably show at most for 5 to 10 seconds before the user moves to a new activity.

Why don’t I remove them altogether? Because I do make some money from them and even more importantly one of my in app purchases is to remove ads (which I’ve made an ok number of sales on). So I just opted to leave the poor performing ads in there.

Now I’m tired of seeing eCPM of .05 on these and a CTR of .12%. I’m ready to do something about it. I’ve always thought it would be perfect to have the ads constant at the bottom and only refresh them every 2 minutes regardless of the activity. But I never really knew how to do it. I recently saw this and it talked about having the same ad across multiple screens but didn’t tell how it acomplished it.

So I went searching and saw somebody suggest this

I’m keeping in mind that you can afford to leak 1 activity, as this is the only solution I know: Declare a static view, say myAdView in your 1st activity (in which you are requesting ad). Now you can ad and remove this myAdView in every activity transation. Ofcource you will have to maintain seperate LinearLayouts for ur ads in seperate activities, where we will add/remove the myAdView eg. Suppose you are going from activity A to B, then in A’s onPause remove myAdView:

private LinearLayout layoutAd;
layoutAd = (LinearLayout) findViewById(; // from A’s xml
protected void onPause() {
and in B’s onResume add the same (FirstActivity’s) myAdView:

private LinearLayout layoutAd;
layoutAd = (LinearLayout) findViewById(; // from B’s xml
protected void onResume() {

But this just seems messy and wrong to me. Even though they say it works.

Somebody in that post suggested fragments. But when I looked more into how fragments worked I realized that each instance of that fragment is tied to one activity and adding the fragment to another meant creating antoher instance of that fragment. Definately doesn’t solve my problem.

Saw this which talked about retaining instance of a fragment. But in this example the fragment being retained was just a background thread and the main fragment UI got recreated. Plus is was still tied to one activity.

So while I was thinking about fragments I thought the best way would be to have one main activity that the user stays in… it has my action bar at the top and an ad at the bottom. The ad refreshes every 2 minutes. Then change each of my activites into fragments. And replace the same middle section with differnt fragments as the user navigates through the game. I made a little test app and this seemed to work fine. I do need to make sure the fragments get disposed of correctly since I will be constantly creating new ones and replacing the old ones (just like I currently do with my activities).

Does anybody know of a better way to accomplish a static ad at the bottom that can refresh when I want it to instead of during each new activity? Anything wrong with the method I’m thinking about? It seems like it will be alot of work but I don’t know a better way of doing it.

I remember to read somewhere about that topic and how to rearrange your activity logic to work inside of FrameViews.

That way, your ad layer is always visible and you can control it over the refresh.

I cannot remember where I read about it because it was not that important for me, but you may get an idea of what to search for. It was pretty straight forward and did fit well in the activity lifecylcle as far as i remember.

That’s the way I would do it. Just keep one Activity with a static AdView, and turn your current Activities into Fragments. It’ll take a bit of re-engineering, but it does seem to be the way Google’s suggesting apps be built these days.

It will also make things a lot easier if you want to adapt for a tablet layout. The Google Play app is a prime example - it’s made up entirely of fragments, so that it can use the same code & layout files for the phone & tablet versions.

Update. It was actually alot easier than I thought converting my current activities into fragments. I just released the update to the market with the static adview at the bottom and action bar at the top with the middle being the activity fragments. We will see how this affects my CTR and eCMP. But more importantly if it has any affect on my ad earning for that app. I created a new ad unit in MoPub so I can track this separately from the ads still being served to old versions.

i just released the update to the market with the static adview at the bottom and action bar at the top with the middle being the activity fragments