danijoo
danijoo

Reputation: 2843

android Inapp Billing: remove ads

In my android app, im showing some small ad banners at the bottom of the screen in some activities. I now want to give the user the opportunity to remove this ads via in-app billing.

What is a good way to implement that?

As the ads are showing up immediatly after the start of some activities, querying googles service for purchased items every time i am showing an ad seems to be bad as it takes some time to connect to the service. I thought about querying googles service once while in a splash screen, using a boolean in my application context singelton to store the information if adfree is purchased. In the activities onCreate, I then check if boolean isPremium is true. If this is the case, im setting the visibility of the adview to false findViewById(R.id.adview).setVisibility(false).

Is this safe? Im not sure if the ApplicationManager can kill my ApplicationContext where the variable is stored without killing all activities.

Upvotes: 3

Views: 1419

Answers (2)

Somen Tushir
Somen Tushir

Reputation: 199

This is the best way to remove ads after purchase

if (!bp.isPurchased("prime")  {
        mAdView = (AdView) findViewById(R.id.adView1);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);


    }else if(bp.isPurchased("prime") ){
        mAdView = (AdView) findViewById(R.id.adView1);

        mAdView.setVisibility(View.GONE);

    }

I am using https://github.com/anjlab/android-inapp-billing-v3 library

Upvotes: 0

Nikolay Elenkov
Nikolay Elenkov

Reputation: 52936

Use a Boolean and set the variable to null. Then only query once if it is null (lazy init). If your app gets killed it will start out as null and you will simply query again. Also probably a better idea to actually remove the AdViews otherwise they will continue to issue ad requests and you will get very low CTR.

Upvotes: 1

Related Questions