Leadbolt ad integration in libgdx

222 Views Asked by At

I'm new in Libgdx and I'm trying to show leadbolt ads in my app. i've found a forum thread http://www.badlogicgames.com/forum/viewtopic.php?f=11&t=9072&p=41323#p41323 about communicating with android and libgdx. I've build the related interfaces and etc. interface works well, i've tried to give message on showAd() and it works well. But when i'm trying to add the given code from leadbolt, it shows error on "this". Code is attached below. I guess that this has a very simple solution but my java knowledge not enough for this solution :)

public class AndroidBrowserOpener implements ActionResolver{

private AdController ad;

@Override
public void showAd() {
    // TODO Auto-generated method stub

    ad = new AdController(this, "my ad id");
    ad.loadAd();

}

}

My Main Activity

public class MainActivity extends AndroidApplication {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    initialize(new fatNinja(new AndroidBrowserOpener()));

    super.onCreate(savedInstanceState);
}

}

Core Interface

public interface ActionResolver {
public void showAd();
 }

I'm calling showAd() from the main inside create().

Thanks for the replies.

Edit:

Thanks for the answer, i've found a context example from badlogic forums like below, but not showing ads. it gives error: E/LBAdController(5088): loadAd() failed - A Valid Activity not passed code is below:

public class AndroidBrowserOpener implements ActionResolver {

private AdController ad;

public AndroidBrowserOpener(Context context){
    ad = new AdController(context, "my id");
}

@Override
public void showAd() {
    // TODO Auto-generated method stub

    ad.loadAd();        
    System.out.println("it works");
}

}
1

There are 1 best solutions below

0
On

use Adlistner instead of this . i think it will work

if posted code is complete code than you have to understand the use of interface used. You have to send the context to call the method. plz understand the calling of that method