Nam Vu
Nam Vu

Reputation: 5725

Display Ads from Android service

I can display my ads like this:

final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {
                displayInterstitial();
                handler.postDelayed(this, 240000);
            }
        }, 100000);

How can i displayInterstitial() independent with activity?

That mean i want to show displayInterstitial() from any activity of my application.

Should i use service to display this? And if yes, how can i stop handler when my application in background.

Thank you

Upvotes: 0

Views: 174

Answers (1)

Squonk
Squonk

Reputation: 48871

Create a 'base' Activity which includes the code for displaying your ads.

Example...

public class MyBaseActivity extends Activity {

    // Put the code for displaying the ads into methods in this
    // Activity following the guidelines from your ad provider

}

Once you've done that you simply need to extend your base Activity as follows...

public class FirstActivity extends MyBaseActivity {
    ...
}

public class SecondActivity extends MyBaseActivity {
    ...
}

If you need to you just have to call the super methods of the base Activity in order to turn on or turn off the ads.

Upvotes: 1

Related Questions