Hello everyone.
I’ll try to display admob on Android Device.
Curiously, When I run my game. First Time, I can’t see addView screen.
But Lock and UnLock, If I come back my game. Then I can see addView without any problem.
I’m searching many code snip.
But I don’t find correct answoer.
This just my own isseu? Kindly can you check my source code.
Why,First Time, I can’t see admob screen.
Hello suveerjacob.
First Thanks for your reply.
I changed my code as below. But Result is same.
Currently, I don’t want to detail control about admob.
Just Display fixed area from game start to end
(I found, If we want to detail control we have to integrate with JNI)
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
me = this;
{
@Override
public void run()
{
LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(
getWindowManager().getDefaultDisplay().getWidth(),
LinearLayout.LayoutParams.WRAP_CONTENT);
adView = new AdView(me);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE")
.build();
adView.loadAd(adRequest);
addContentView(adView, adParams);
}
} );
Maybe, This is not thread issue. Why, First time my adview under Game Screen(Always)
After long time,result is same.
But,I already told this situation. After Locking Android screen and unlock, re-entrance my game.
Then, Admob display top of screen correctly.
very interesting, but I don’t know reason.
Thanks.
yes it is because there is a difference between the solution i gave to you n the solution you are trying…
just try:
me.runOnUiThread(new Runnable() {
public void run() {
// Insert your admob code here.
}
});
from the above solution i can see that you are not using ‘me.runOnUiThread(…)’
I dont know the exact n detailed explanation of runOnUiThread(…), use it n let me know if it is working or not…
There can be another problem that you are calling AdView in constructor before the before loading cocos2dx libraries…
For tat problem, yes have to manage ad initialization from your c++ code, i.e you have to use JNI.
For JNI you can google it. I am sending some links you can refer it… http://www.cocos2d-x.org/wiki/How_to_use_jni
Hello.
I found solution. This is not JNI issue.
Simpley, This is come from admob with using google play service.
For solving this issue, I just add below line
Hi… when game is running with google ad (google services) … I lock the screen and unlock the screen and the ad dissappers… I tried the solution above… atleast my ad shows… but unless revmob loads an another ad the google ad doesnt show… pls help
to ymkimwizard,
firstly i want to thank you very much because i was having the very same problem, and searching all around to try to solve it, at last your solution worked for me. (i was thinking that it might because of the child index problem, and tried to bring adview to front, but failed)
but i still don’t know how you found the solution, because i couldn’t see any relationship between your reference link “how-to-duplicate-sprite-of-sprites-in-cocos2d-x-2-1-4” and your solution, which solve the problem by calling setBackgroundColor function of adview, maybe you can point out that if you someday come back to this thread.