- Home /
Hide/Show Admob View Android plugin
I am showing admob in my unity app. I want to hide admob on another scene. Here is the code showing how I am making admob view and importing it to unity as plugin. AdMob is showing perfectly fine. Now my concern is how to hide and show it again using some function calls.
public class AdMob
{
private String pubID = "xxxx"; //Your public AdMob ID. Make sure this is correct, or you wont get any credit for the Ad.
private Activity activity; //Store the android main activity
private AdView adView; //The AdView we will display to the user
private RelativeLayout layout; //The layout the AdView will sit on
//Constructor
AdMob()
{
activity = UnityPlayer.currentActivity;
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
layout = new RelativeLayout(activity);
activity.addContentView(layout,new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
adView = new AdView(activity,AdSize.SMART_BANNER,pubID);
adView.loadAd(new AdRequest());
AdView.LayoutParams adViewParams = new AdView.LayoutParams(AdView.LayoutParams.WRAP_CONTENT,
AdView.LayoutParams.WRAP_CONTENT);
//the next line is the key to putting it on the bottom
adViewParams.addRule(AdView.ALIGN_PARENT_BOTTOM);
layout.addView(adView.getRootView(),adViewParams);
}
});
}
Now I want to write a function something like this which I will call while switching my scenes. Same thing goes with showing admob.
public void hideAdmob(){
adView.setVisibility(View.GONE);
}
but this thing or other tries just crashes my app when I switch scene.
Any help guys. Thanks a lot.
Your answer
Follow this Question
Related Questions
Using Ad plugins on Android leads to extra crashes 0 Answers
App stops working as soon it starts. 0 Answers
admob plugin for ios and android 1 Answer
Unity Android plugin problem build CommandInvokationFailure 2 Answers
AdMob Ads Not Showing in Android 0 Answers