0
我是Libgdx和AdMob的新用戶。最近我一直在努力讓兩者合作。每當我在我的設備上通過Eclipse啓動應用程序時,它什麼都不做,一段時間後我的筆記本電腦太慢了,我猜測有內存泄漏。AdMob with LibGDX 1.2.0內存泄漏
我已經檢查了所有的官方和非官方的教程,甚至在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造成的原因嗎?我在您發佈的代碼中沒有看到任何memleak的跡象。如果有的話,它可能在你遊戲的代碼中。 – Tenfour04
嗯。那麼就不會有一個,因爲我試着用我的遊戲代碼和libgdx的默認「測試遊戲」,它只顯示紅色背景中的libgdx的橫幅,但仍然得到相同的結果......這看起來是否類似到你的admob代碼,我只是想確定這不是這些代碼行爲的原因。謝謝你的回答! – samynoname