I have been struggling with this problem for a while now and would be very grateful if anyone could help me out.
The problem is that when I´ve successfully loaded an airpush "smartwall" it "clicks" itself and I immediately go to wherever the ad takes you. Before the ad has completed loading I can see the graphical representation of the ad loading.
I´ve contacted AP-support several times but I´m still having the same problem no matter what I do.
The problem seems to be that the smartwall is running on the wrong thread, I am using a UIThread handler for other stuff and it works fine (leadbolt interstitials, alertdialogs and other native android stuff).
Things I´ve tried:
AsyncTask
@Override
public void showAP() {
uiThread.post(new Runnable(){
public void run(){
new Async().execute();
}
});
}
private class Async extends AsyncTask<String, Integer, String[]>{
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String[] doInBackground(String... params) {
if(apSmartWall == null)
apSmartWall = new ApSmartWall(MainActivity.this, adCallbackListener);
apSmartWall.startSmartWallAd();
return null;
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
}
@Override
protected void onPostExecute(String[] result) {
super.onPostExecute(result);
}
}
Handler
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
apSmartWall = new ApSmartWall(MainActivity.this, adCallbackListener);
// Create the layout
layout = new RelativeLayout(this);
// Do the stuff that initialize() would do for you
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// Create the libgdx View
gameView = initializeForView(new Game(this), true);
// Add the libgdx view
layout.addView(gameView);
context = this;
uiThread = new Handler();
... (adding another view for mopub here, but removing this doesn´t change anything)
// Hook it all up
setContentView(layout);
}
@Override
public void showAP() {
uiThread.post(new Runnable(){
public void run(){
apSmartWall.startSmartWallAd();
}
});
}
libGDX Thread stuff: https://code.google.com/p/libgdx/wiki/TheArchitecture#The_Graphics_Module
I also tried using libGDX built in handler method, AndroidApplication.runOnUiThread() but that didn´t work either. I am by no means experienced when it comes to native Android so there might be something I´ve done wrong. But like I said it´s working fine for other stuff that runs on the UI Thread, for example this works fine:
@Override
public void resumeAds() {
uiThread.post(new Runnable(){
public void run() {
moPubView = new MoPubView(context);
// non-tablet
if(width >= 728)
moPubView.setAdUnitId(TABLET_SIZE);
else
moPubView.setAdUnitId(PHONE_SIZE);
moPubView.loadAd();
RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layout.addView(moPubView, adParams);
}
});
}
AndroidManifest.xml airpush things
<meta-data android:name="com.package.APPID" android:value="appid" />
<meta-data android:name="com.package.APIKEY" android:value="android*key"/>
<activity android:exported="false" android:name="com.package.SmartWallActivity"
android:configChanges="orientation|screenSize"
android:theme="@android:style/Theme.Translucent" />
<activity android:name="com.package.BrowserActivity"
android:configChanges="orientation|screenSize" />