【问题标题】:AdMob with LibGDX 1.2.0 Memory LeakAdMob 与 LibGDX 1.2.0 内存泄漏
【发布时间】:2014-07-07 16:17:46
【问题描述】:

我是 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>

我真的非常感谢任何笔记!

【问题讨论】:

  • 您认为这是由 AdMob 引起的吗?我在您发布的代码中没有看到任何内存泄漏的迹象。如果有,它可能在您的游戏代码中。
  • 嗯。好吧,不应该有一个,因为我用我的游戏代码和默认的 libgdx 的“测试游戏”尝试了这个,它只在红色背景中显示 libgdx 的横幅,但仍然得到相同的结果......这看起来相似吗对于您的 admob 代码,我只想确定这不是这些代码行的原因。谢谢你的回答!!

标签: android eclipse memory-leaks libgdx admob


【解决方案1】:

哇...经过这么长时间我终于找到了答案。 答案在此处详细描述:

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

Eclipse 似乎缺少内存来构建项目。

【讨论】:

    猜你喜欢
    • 2014-09-18
    • 1970-01-01
    • 2016-10-16
    • 1970-01-01
    • 2015-07-20
    • 2016-09-29
    • 1970-01-01
    • 2015-02-26
    • 2016-03-09
    相关资源
    最近更新 更多