0

I'm new to Libgdx and also to AdMob. Recently I've been trying to get both to work together. How ever everytime when I start the app on my device over Eclipse it just does nothing and after a time my notebook is so slow, I'm guessing that there is a memory leak.

I've checked all official and unofficial tutorials and even notes and codes on github of libgdx and other people but I just can't find a clue why it wouldn't work.

Is there anybody out there having running example codes of the newest Libgdx (1.2.0) with the newest AdMob?

So this is what I have, note: I left BANNER_ID and TEST_ID out.

package com.samynoname.treasurebox.android;

import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;

import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.samynoname.treasurebox.TreasureBox;

public class AndroidLauncher extends AndroidApplication {

  private static final String BANNER_ID = "MY ID";
  private static final String TEST_DEVICE_ID = "TEST ID";

  protected AdRequest requestAd;
  protected AdView bannerAd;


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

    AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    FrameLayout layout = new FrameLayout(this);

    TreasureBox game = new TreasureBox();

    View gameView = initializeForView(game, config);

    requestAd = new AdRequest.Builder().addTestDevice(TEST_DEVICE_ID).build();

    bannerAd = new AdView(this);
    bannerAd.setAdSize(AdSize.BANNER);
    bannerAd.setAdUnitId(BANNER_ID);
    bannerAd.loadAd(requestAd);

    bannerAd.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT,
            Gravity.TOP));

    layout.addView(gameView, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
    layout.addView(bannerAd);

    setContentView(layout);
    }
}

And this is my Manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.samynoname.treasurebox.android"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/GdxTheme" >
    <activity
        android:name="com.samynoname.treasurebox.android.AndroidLauncher"
        android:label="@string/app_name" 
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.google.android.gms.ads.AdActivity"
         android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

    <!-- Google play services -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <!-- Google play Admobs -->
    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

</application>

I'm really really thankful for any notes!

samynoname
  • 11
  • 3
  • 2
    Is there a reason you think it's caused by AdMob? I don't see any indications of a memleak in the code you posted. If there is one, it's probably in your game's code. – Tenfour04 Jul 08 '14 at 00:40
  • Hm. well there shoulnd't be one as I tried this with my game codes and also with the default "test-game" of libgdx which only shows the banner of libgdx in red background but still get the same results... does this looks similar to your codes of admob, I just want to be sure that it is not these lines of codes to be the cause. Thank you for the answer!! – samynoname Jul 09 '14 at 09:03

1 Answers1

1

Wow... after such a long time I finally found an answer. The answer is described here in further details:

https://stackoverflow.com/a/6024262/2896954

It seems like Eclipse was lacking memory to build the project.

Community
  • 1
  • 1
samynoname
  • 11
  • 3