AdMob与LibGDX 1.2.0内存泄漏

时间:2014-07-07 16:17:46

标签: android eclipse memory-leaks libgdx admob

我是Libgdx的新手,也是AdMob的新手。最近我一直试图让两者一起工作。每次我在设备上通过Eclipse启动应用程序时,它都没有做任何事情,经过一段时间我的笔记本电脑速度很慢,我猜测存在内存泄漏。

我已经检查了libgdx和其他人的github上的所有官方和非官方教程甚至注释和代码,但我找不到线索为什么它不起作用。

有没有人使用最新的AdMob运行最新的Libgdx(1.2.0)的示例代码?

所以这就是我所拥有的,请注意:我离开了BANNER_ID和TEST_ID。

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);
    }
}

这是我的清单文件:

<?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>

我非常感谢任何笔记!

1 个答案:

答案 0 :(得分:1)

哇......经过这么长时间,我终于找到了答案。 答案在此处进一步详细说明:

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

Eclipse似乎缺乏构建项目的记忆。