Implementing admob for different activities

前端 未结 3 1226
一整个雨季
一整个雨季 2020-12-03 03:46

I have three activities in total and i am implementing admob for each activity, every activity has its own banner and when the activity is changes the other activity hangs a

3条回答
  •  旧时难觅i
    2020-12-03 04:30

    The ideal way is to use fragments for each of your screens. This way, you'd use a single activity having a single adview.

    If you want to use multiple activities instead, then the only workaround I know of is to use a static method to load the ads:

    public class MyAdView {
        public static void SetAD(AdView adView){  
            AdRequest adRequest = new AdRequest.Builder()
                .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
                .build();
            adView.loadAd(adRequest);
        }
    
    }
    

    Usage:

    public class SomeActivity extends Activity {
        private AdView adView;  
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.caller_main);
            MyAdView.SetAd((AdView)findViewById(R.id.adView));
        }   
    }
    

提交回复
热议问题