我尝试使用AdMobsAdsSdk6.0.1在我的Android应用中添加AdMob横幅。 横幅显示正确,但会将电话任务管理器中显示的内存使用量从2 MB增加到10 MB。 DDMS显示约。 5MB。我已经阅读了一些关于旧版本中可能的内存泄漏的文章,但找不到解决我问题的任何内容。我用一个简单的测试应用程序重现了这种行为。
活动仅包含AdView
public class TestActivity extends Activity {
private AdView adView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
adView = new AdView(this, AdSize.BANNER, "adunitid");
LinearLayout layout = (LinearLayout) findViewById(R.id.content_Layout);
layout.addView(adView);
adView.loadAd(new AdRequest());
}
@Override
protected void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}
Manifest也只是教程中的副本
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="admobtest.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="13" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".TestActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
</application>
</manifest>
我也试图通过xml包含横幅,但我终于得到了相同的结果。切换到风景和背景可以进一步提高记忆力。我错过了什么或者有人能给我一些提示如何解决这个问题?我以为adView.destroy解决了内存泄漏问题。