I would like to show banners in a fragment instead of an activity, how can I do this?
My Fragment:
Variables:
RevMob revmob;
Activity currentActivity;
Functions:
My Code:
public void startRevMobSession(){
currentActivity = this;
revmob = RevMob.startWithListener(currentActivity, new RevMobAdsListener() {
@Override public void onRevMobSessionStarted() {loadBanner();}
@Override public void onRevMobSessionNotStarted(String message) {}});
}
public void loadBanner() {
revmob.showBanner(currentActivity, Gravity.BOTTOM, null, new RevMobAdsListener() {
@Override public void onRevMobAdReceived() {}
@Override public void onRevMobAdNotReceived(String message) {}
@Override public void onRevMobAdDismissed() {}
@Override public void onRevMobAdClicked() {}
@Override public void onRevMobAdDisplayed() {}});
}
onCreate:
startRevMobSession();
It's working when I'm using it in an activity, but I would like to use it in a fragment. How can I do so?
In a fragment you should do:
currentActivity = getActivity();
instead of
currentActivity = this;
That's the only difference, it should all work properly then.