与admob广告单元ID混淆 [英] Confusion with admob ad unit ids
问题描述
我遵循了
I followed the tutorial to create an ad banner in my app. This works so far, I can see the test ad. However, the tutorial instructs me to use two different ad-ids in two different locations:
in the activity:
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
in the layout:
ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
Question 1: What is the difference between the two ids? Why are they different? What's the purpose?
I have created an account at admob and also an ad unit. The ad unit id looks similar to the second one of the two above (it contains a slash). However, I couldn't find anywhere another id with a tilde, like the first one of the two above.
Question 2: Should I just use the one actual ad unit id I have in both locations in the code? If yes, why is this so redundant?
Question 3: My app actually consists of two activities. Can I use the same ad unit id in both activities?
Question 4: Do I have to do the MobileAds initialization in all activities?
1) The ID you put into the initialize
method is your app ID, so each one of your apps is gonna have a different ID. The second one that you set in your banner view is the ad unit ID. Each ad banner should have a different ID.
2) No. They are different.
3) No, you should use one ad unit ID per ad banner. If you want to add two banners, get two IDs from AdMob
4) No, the initialize
method should only be called once per launch.
To get the ID with the ~
,
- go to
apps.admob.com
- On the tool bar on the left, click the icon with the 9 little squares
- In the popup thingy, click "View All Applications" on the bottom right
- Click on this button to copy the ID for the app you want:
这篇关于与admob广告单元ID混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!