Confusion with admob ad unit ids

这一生的挚爱 提交于 2019-12-23 22:07:50

问题


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:

  1. in the activity:

    MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");

  2. 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:


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:



来源:https://stackoverflow.com/questions/47121317/confusion-with-admob-ad-unit-ids

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!